summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorEric Andersen1999-10-18 19:02:32 +0000
committerEric Andersen1999-10-18 19:02:32 +0000
commitbed30e97005aca748a44806399c646633038daa8 (patch)
treecdba32234f059656b0279b324ae28c742692cd0c /coreutils
parent9b5871888989b16f94cbba5dd304ac444def3afd (diff)
downloadbusybox-bed30e97005aca748a44806399c646633038daa8.zip
busybox-bed30e97005aca748a44806399c646633038daa8.tar.gz
More fixes
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cp.c10
-rw-r--r--coreutils/ls.c2
-rw-r--r--coreutils/mv.c76
-rw-r--r--coreutils/rm.c105
-rw-r--r--coreutils/sync.c11
5 files changed, 133 insertions, 71 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 4016fc7..c5e34d3 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -48,7 +48,7 @@ static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
strcpy(newdestName, destName);
- if (dirFlag==TRUE && newdestName[strlen(newdestName)-1]!= '/' ) {
+ if (dirFlag==TRUE) {
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(fileName, skipName));
@@ -104,10 +104,12 @@ extern int cp_main(int argc, char **argv)
while (argc-- > 1) {
srcName = *(argv++);
skipName = strrchr(srcName, '/');
- if (skipName) skipName++;
- if (recursiveAction(srcName, recursiveFlag, followLinks,
- fileAction, fileAction) == FALSE)
+ if (skipName)
+ skipName++;
+ if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
+ fileAction, fileAction) == FALSE) {
exit( FALSE);
+ }
}
exit( TRUE);
}
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 50b983e..2e3d50e 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -68,7 +68,7 @@ static int dirAction(const char *fileName)
exit(FALSE);
}
while ((entry = readdir(dir)) != NULL) {
- recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, fileAction, dirAction);
+ recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, FALSE, fileAction, dirAction);
}
return( TRUE);
}
diff --git a/coreutils/mv.c b/coreutils/mv.c
index 10a0822..2a7c8c1 100644
--- a/coreutils/mv.c
+++ b/coreutils/mv.c
@@ -21,63 +21,59 @@
#include "internal.h"
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+#include <time.h>
#include <utime.h>
-#include <errno.h>
+#include <dirent.h>
-const char mv_usage[] = "source-file [source-file ...] destination-file\n"
- "\n" "\tMove the source files to the destination.\n" "\n";
+static const char mv_usage[] = "mv SOURCE DEST\n"
+" or: mv SOURCE... DIRECTORY\n"
+"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
-extern int mv_main (int argc, char **argv)
+static const char *srcName;
+static const char *destName;
+static const char *skipName;
+static int dirFlag = FALSE;
+
+
+extern int mv_main(int argc, char **argv)
{
- const char *srcName;
- const char *destName;
- const char *lastArg;
- int dirFlag;
+ char newdestName[NAME_MAX];
if (argc < 3) {
- fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
+ fprintf(stderr, "Usage: %s", mv_usage);
exit (FALSE);
}
- lastArg = argv[argc - 1];
+ argc--;
+ argv++;
- dirFlag = isDirectory (lastArg);
+ destName = argv[argc - 1];
+ dirFlag = isDirectory(destName);
- if ((argc > 3) && !dirFlag) {
- fprintf (stderr, "%s: not a directory\n", lastArg);
+ if ((argc > 3) && dirFlag==FALSE) {
+ fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
- while (argc-- > 2) {
- srcName = *(++argv);
-
- if (access (srcName, 0) < 0) {
- perror (srcName);
- continue;
+ while (argc-- > 1) {
+ srcName = *(argv++);
+ skipName = strrchr(srcName, '/');
+ if (skipName)
+ skipName++;
+ strcpy(newdestName, destName);
+ if (dirFlag==TRUE) {
+ strcat(newdestName, "/");
+ if ( skipName != NULL)
+ strcat(newdestName, strstr(srcName, skipName));
}
-
- destName = lastArg;
-
- if (dirFlag==TRUE)
- destName = buildName (destName, srcName);
-
- if (rename (srcName, destName) >= 0)
- continue;
-
- if (errno != EXDEV) {
- perror (destName);
- continue;
+ if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
+ exit( FALSE);
}
-
- if (!copyFile (srcName, destName, TRUE, FALSE))
- continue;
-
- if (unlink (srcName) < 0)
+ if (unlink (srcName) < 0) {
perror (srcName);
+ exit( FALSE);
+ }
}
- exit (TRUE);
+ exit( TRUE);
}
diff --git a/coreutils/rm.c b/coreutils/rm.c
index dc35b02..477d3af 100644
--- a/coreutils/rm.c
+++ b/coreutils/rm.c
@@ -1,30 +1,93 @@
+/*
+ * Mini rm implementation for busybox
+ *
+ * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
#include "internal.h"
-#include <errno.h>
+#include <stdio.h>
+#include <time.h>
+#include <utime.h>
+#include <dirent.h>
+
+static const char* rm_usage = "Usage: rm [OPTION]... FILE...\n"
+"Remove (unlink) the FILE(s).\n\n"
+"\t-f\tremove existing destinations, never prompt\n"
+"\t-r\tremove the contents of directories recursively\n";
+
+
+static int recursiveFlag = FALSE;
+static int forceFlag = FALSE;
+static const char *srcName;
+
-const char rm_usage[] = "rm [-r] file [file ...]\n"
-"\n"
-"\tDelete files.\n"
-"\n"
-"\t-r:\tRecursively remove files and directories.\n";
+static int fileAction(const char *fileName, struct stat* statbuf)
+{
+ if (unlink( fileName) < 0 ) {
+ perror( fileName);
+ return ( FALSE);
+ }
+ return ( TRUE);
+}
-extern int
-rm_main(struct FileInfo * i, int argc, char * * argv)
+static int dirAction(const char *fileName, struct stat* statbuf)
{
- i->processDirectoriesAfterTheirContents = 1;
- return monadic_main(i, argc, argv);
+ if (rmdir( fileName) < 0 ) {
+ perror( fileName);
+ return ( FALSE);
+ }
+ return ( TRUE);
}
-extern int
-rm_fn(const struct FileInfo * i)
+extern int rm_main(int argc, char **argv)
{
- if ( i->recursive
- && !i->isSymbolicLink
- && (i->stat.st_mode & S_IFMT) == S_IFDIR )
- return rmdir_fn(i);
- else if ( unlink(i->source) != 0 && errno != ENOENT && !i->force ) {
- name_and_error(i->source);
- return 1;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s", rm_usage);
+ exit (FALSE);
+ }
+ argc--;
+ argv++;
+
+ /* Parse any options */
+ while (**argv == '-') {
+ while (*++(*argv))
+ switch (**argv) {
+ case 'r':
+ recursiveFlag = TRUE;
+ break;
+ case 'f':
+ forceFlag = TRUE;
+ break;
+ default:
+ fprintf(stderr, "Usage: %s\n", rm_usage);
+ exit(FALSE);
+ }
+ argc--;
+ argv++;
+ }
+
+ while (argc-- > 0) {
+ srcName = *(argv++);
+ if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
+ fileAction, dirAction) == FALSE) {
+ exit( FALSE);
}
- else
- return 0;
+ }
+ exit( TRUE);
}
diff --git a/coreutils/sync.c b/coreutils/sync.c
index 6fa5b38..e7aa445 100644
--- a/coreutils/sync.c
+++ b/coreutils/sync.c
@@ -1,11 +1,12 @@
#include "internal.h"
-const char sync_usage[] = "sync\n"
-"\n"
-"\tWrite all buffered filesystem blocks to disk.\n";
-
extern int
-sync_main(struct FileInfo * i, int argc, char * * argv)
+sync_main(int argc, char * * argv)
{
+ if ( **(argv+1) == '-' ) {
+ fprintf(stderr, "Usage: sync\nWrite all buffered filesystem blocks to disk.\n");
+ exit(FALSE);
+ }
return sync();
}
+