aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-18 19:02:32 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-18 19:02:32 +0000
commitbed30e97005aca748a44806399c646633038daa8 (patch)
treecdba32234f059656b0279b324ae28c742692cd0c
parent9b5871888989b16f94cbba5dd304ac444def3afd (diff)
downloadbusybox-w32-bed30e97005aca748a44806399c646633038daa8.tar.gz
busybox-w32-bed30e97005aca748a44806399c646633038daa8.tar.bz2
busybox-w32-bed30e97005aca748a44806399c646633038daa8.zip
More fixes
-rw-r--r--busybox.def.h4
-rw-r--r--chmod_chown_chgrp.c2
-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
-rw-r--r--cp.c10
-rw-r--r--find.c33
-rw-r--r--findutils/find.c33
-rw-r--r--internal.h2
-rw-r--r--ls.c2
-rw-r--r--mv.c76
-rw-r--r--rm.c105
-rw-r--r--swapoff.c2
-rw-r--r--sync.c11
-rw-r--r--umount.c7
-rw-r--r--util-linux/umount.c7
-rw-r--r--utility.c51
19 files changed, 295 insertions, 254 deletions
diff --git a/busybox.def.h b/busybox.def.h
index 15c8edc43..10a55f409 100644
--- a/busybox.def.h
+++ b/busybox.def.h
@@ -39,12 +39,12 @@
39//#define BB_PRINTF 39//#define BB_PRINTF
40#define BB_PWD 40#define BB_PWD
41#define BB_REBOOT 41#define BB_REBOOT
42//#define BB_RM 42#define BB_RM
43#define BB_RMDIR 43#define BB_RMDIR
44#define BB_SLEEP 44#define BB_SLEEP
45////#define BB_SWAPOFF 45////#define BB_SWAPOFF
46//#define BB_SWAPON 46//#define BB_SWAPON
47//#define BB_SYNC 47#define BB_SYNC
48#define BB_TAR 48#define BB_TAR
49#define BB_TOUCH 49#define BB_TOUCH
50#define BB_TRUE 50#define BB_TRUE
diff --git a/chmod_chown_chgrp.c b/chmod_chown_chgrp.c
index f3d8ce207..27c02fe54 100644
--- a/chmod_chown_chgrp.c
+++ b/chmod_chown_chgrp.c
@@ -138,7 +138,7 @@ int chmod_chown_chgrp_main(int argc, char **argv)
138 exit( FALSE); 138 exit( FALSE);
139 } 139 }
140 while (argc-- > 1) { 140 while (argc-- > 1) {
141 if (recursiveAction( *(++argv), recursiveFlag, TRUE, fileAction, fileAction)==FALSE) 141 if (recursiveAction( *(++argv), recursiveFlag, TRUE, FALSE, fileAction, fileAction)==FALSE)
142 exit( FALSE); 142 exit( FALSE);
143 } 143 }
144 exit(TRUE); 144 exit(TRUE);
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 4016fc760..c5e34d333 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -48,7 +48,7 @@ static int fileAction(const char *fileName, struct stat* statbuf)
48{ 48{
49 char newdestName[NAME_MAX]; 49 char newdestName[NAME_MAX];
50 strcpy(newdestName, destName); 50 strcpy(newdestName, destName);
51 if (dirFlag==TRUE && newdestName[strlen(newdestName)-1]!= '/' ) { 51 if (dirFlag==TRUE) {
52 strcat(newdestName, "/"); 52 strcat(newdestName, "/");
53 if ( skipName != NULL) 53 if ( skipName != NULL)
54 strcat(newdestName, strstr(fileName, skipName)); 54 strcat(newdestName, strstr(fileName, skipName));
@@ -104,10 +104,12 @@ extern int cp_main(int argc, char **argv)
104 while (argc-- > 1) { 104 while (argc-- > 1) {
105 srcName = *(argv++); 105 srcName = *(argv++);
106 skipName = strrchr(srcName, '/'); 106 skipName = strrchr(srcName, '/');
107 if (skipName) skipName++; 107 if (skipName)
108 if (recursiveAction(srcName, recursiveFlag, followLinks, 108 skipName++;
109 fileAction, fileAction) == FALSE) 109 if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
110 fileAction, fileAction) == FALSE) {
110 exit( FALSE); 111 exit( FALSE);
112 }
111 } 113 }
112 exit( TRUE); 114 exit( TRUE);
113} 115}
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 50b983e24..2e3d50e9f 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -68,7 +68,7 @@ static int dirAction(const char *fileName)
68 exit(FALSE); 68 exit(FALSE);
69 } 69 }
70 while ((entry = readdir(dir)) != NULL) { 70 while ((entry = readdir(dir)) != NULL) {
71 recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, fileAction, dirAction); 71 recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, FALSE, fileAction, dirAction);
72 } 72 }
73 return( TRUE); 73 return( TRUE);
74} 74}
diff --git a/coreutils/mv.c b/coreutils/mv.c
index 10a082210..2a7c8c1f3 100644
--- a/coreutils/mv.c
+++ b/coreutils/mv.c
@@ -21,63 +21,59 @@
21 21
22#include "internal.h" 22#include "internal.h"
23#include <stdio.h> 23#include <stdio.h>
24#include <sys/types.h> 24#include <time.h>
25#include <sys/stat.h>
26#include <fcntl.h>
27#include <utime.h> 25#include <utime.h>
28#include <errno.h> 26#include <dirent.h>
29 27
30const char mv_usage[] = "source-file [source-file ...] destination-file\n"
31 "\n" "\tMove the source files to the destination.\n" "\n";
32 28
29static const char mv_usage[] = "mv SOURCE DEST\n"
30" or: mv SOURCE... DIRECTORY\n"
31"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
33 32
34 33
35extern int mv_main (int argc, char **argv) 34static const char *srcName;
35static const char *destName;
36static const char *skipName;
37static int dirFlag = FALSE;
38
39
40extern int mv_main(int argc, char **argv)
36{ 41{
37 const char *srcName; 42 char newdestName[NAME_MAX];
38 const char *destName;
39 const char *lastArg;
40 int dirFlag;
41 43
42 if (argc < 3) { 44 if (argc < 3) {
43 fprintf (stderr, "Usage: %s %s", *argv, mv_usage); 45 fprintf(stderr, "Usage: %s", mv_usage);
44 exit (FALSE); 46 exit (FALSE);
45 } 47 }
46 lastArg = argv[argc - 1]; 48 argc--;
49 argv++;
47 50
48 dirFlag = isDirectory (lastArg); 51 destName = argv[argc - 1];
52 dirFlag = isDirectory(destName);
49 53
50 if ((argc > 3) && !dirFlag) { 54 if ((argc > 3) && dirFlag==FALSE) {
51 fprintf (stderr, "%s: not a directory\n", lastArg); 55 fprintf(stderr, "%s: not a directory\n", destName);
52 exit (FALSE); 56 exit (FALSE);
53 } 57 }
54 58
55 while (argc-- > 2) { 59 while (argc-- > 1) {
56 srcName = *(++argv); 60 srcName = *(argv++);
57 61 skipName = strrchr(srcName, '/');
58 if (access (srcName, 0) < 0) { 62 if (skipName)
59 perror (srcName); 63 skipName++;
60 continue; 64 strcpy(newdestName, destName);
65 if (dirFlag==TRUE) {
66 strcat(newdestName, "/");
67 if ( skipName != NULL)
68 strcat(newdestName, strstr(srcName, skipName));
61 } 69 }
62 70 if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
63 destName = lastArg; 71 exit( FALSE);
64
65 if (dirFlag==TRUE)
66 destName = buildName (destName, srcName);
67
68 if (rename (srcName, destName) >= 0)
69 continue;
70
71 if (errno != EXDEV) {
72 perror (destName);
73 continue;
74 } 72 }
75 73 if (unlink (srcName) < 0) {
76 if (!copyFile (srcName, destName, TRUE, FALSE))
77 continue;
78
79 if (unlink (srcName) < 0)
80 perror (srcName); 74 perror (srcName);
75 exit( FALSE);
76 }
81 } 77 }
82 exit (TRUE); 78 exit( TRUE);
83} 79}
diff --git a/coreutils/rm.c b/coreutils/rm.c
index dc35b0297..477d3af59 100644
--- a/coreutils/rm.c
+++ b/coreutils/rm.c
@@ -1,30 +1,93 @@
1/*
2 * Mini rm implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1#include "internal.h" 22#include "internal.h"
2#include <errno.h> 23#include <stdio.h>
24#include <time.h>
25#include <utime.h>
26#include <dirent.h>
27
28static const char* rm_usage = "Usage: rm [OPTION]... FILE...\n"
29"Remove (unlink) the FILE(s).\n\n"
30"\t-f\tremove existing destinations, never prompt\n"
31"\t-r\tremove the contents of directories recursively\n";
32
33
34static int recursiveFlag = FALSE;
35static int forceFlag = FALSE;
36static const char *srcName;
37
3 38
4const char rm_usage[] = "rm [-r] file [file ...]\n" 39static int fileAction(const char *fileName, struct stat* statbuf)
5"\n" 40{
6"\tDelete files.\n" 41 if (unlink( fileName) < 0 ) {
7"\n" 42 perror( fileName);
8"\t-r:\tRecursively remove files and directories.\n"; 43 return ( FALSE);
44 }
45 return ( TRUE);
46}
9 47
10extern int 48static int dirAction(const char *fileName, struct stat* statbuf)
11rm_main(struct FileInfo * i, int argc, char * * argv)
12{ 49{
13 i->processDirectoriesAfterTheirContents = 1; 50 if (rmdir( fileName) < 0 ) {
14 return monadic_main(i, argc, argv); 51 perror( fileName);
52 return ( FALSE);
53 }
54 return ( TRUE);
15} 55}
16 56
17extern int 57extern int rm_main(int argc, char **argv)
18rm_fn(const struct FileInfo * i)
19{ 58{
20 if ( i->recursive 59
21 && !i->isSymbolicLink 60 if (argc < 2) {
22 && (i->stat.st_mode & S_IFMT) == S_IFDIR ) 61 fprintf(stderr, "Usage: %s", rm_usage);
23 return rmdir_fn(i); 62 exit (FALSE);
24 else if ( unlink(i->source) != 0 && errno != ENOENT && !i->force ) { 63 }
25 name_and_error(i->source); 64 argc--;
26 return 1; 65 argv++;
66
67 /* Parse any options */
68 while (**argv == '-') {
69 while (*++(*argv))
70 switch (**argv) {
71 case 'r':
72 recursiveFlag = TRUE;
73 break;
74 case 'f':
75 forceFlag = TRUE;
76 break;
77 default:
78 fprintf(stderr, "Usage: %s\n", rm_usage);
79 exit(FALSE);
80 }
81 argc--;
82 argv++;
83 }
84
85 while (argc-- > 0) {
86 srcName = *(argv++);
87 if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
88 fileAction, dirAction) == FALSE) {
89 exit( FALSE);
27 } 90 }
28 else 91 }
29 return 0; 92 exit( TRUE);
30} 93}
diff --git a/coreutils/sync.c b/coreutils/sync.c
index 6fa5b380b..e7aa44585 100644
--- a/coreutils/sync.c
+++ b/coreutils/sync.c
@@ -1,11 +1,12 @@
1#include "internal.h" 1#include "internal.h"
2 2
3const char sync_usage[] = "sync\n"
4"\n"
5"\tWrite all buffered filesystem blocks to disk.\n";
6
7extern int 3extern int
8sync_main(struct FileInfo * i, int argc, char * * argv) 4sync_main(int argc, char * * argv)
9{ 5{
6 if ( **(argv+1) == '-' ) {
7 fprintf(stderr, "Usage: sync\nWrite all buffered filesystem blocks to disk.\n");
8 exit(FALSE);
9 }
10 return sync(); 10 return sync();
11} 11}
12
diff --git a/cp.c b/cp.c
index 4016fc760..c5e34d333 100644
--- a/cp.c
+++ b/cp.c
@@ -48,7 +48,7 @@ static int fileAction(const char *fileName, struct stat* statbuf)
48{ 48{
49 char newdestName[NAME_MAX]; 49 char newdestName[NAME_MAX];
50 strcpy(newdestName, destName); 50 strcpy(newdestName, destName);
51 if (dirFlag==TRUE && newdestName[strlen(newdestName)-1]!= '/' ) { 51 if (dirFlag==TRUE) {
52 strcat(newdestName, "/"); 52 strcat(newdestName, "/");
53 if ( skipName != NULL) 53 if ( skipName != NULL)
54 strcat(newdestName, strstr(fileName, skipName)); 54 strcat(newdestName, strstr(fileName, skipName));
@@ -104,10 +104,12 @@ extern int cp_main(int argc, char **argv)
104 while (argc-- > 1) { 104 while (argc-- > 1) {
105 srcName = *(argv++); 105 srcName = *(argv++);
106 skipName = strrchr(srcName, '/'); 106 skipName = strrchr(srcName, '/');
107 if (skipName) skipName++; 107 if (skipName)
108 if (recursiveAction(srcName, recursiveFlag, followLinks, 108 skipName++;
109 fileAction, fileAction) == FALSE) 109 if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
110 fileAction, fileAction) == FALSE) {
110 exit( FALSE); 111 exit( FALSE);
112 }
111 } 113 }
112 exit( TRUE); 114 exit( TRUE);
113} 115}
diff --git a/find.c b/find.c
index c92202b86..1fb219496 100644
--- a/find.c
+++ b/find.c
@@ -62,7 +62,7 @@ static int dirAction(const char *fileName, struct stat* statbuf)
62 while ((entry = readdir(dir)) != NULL) { 62 while ((entry = readdir(dir)) != NULL) {
63 char dirName[NAME_MAX]; 63 char dirName[NAME_MAX];
64 sprintf(dirName, "%s/%s", fileName, entry->d_name); 64 sprintf(dirName, "%s/%s", fileName, entry->d_name);
65 recursiveAction( dirName, TRUE, dereferenceFlag, fileAction, dirAction); 65 recursiveAction( dirName, TRUE, dereferenceFlag, FALSE, fileAction, dirAction);
66 } 66 }
67 return( TRUE); 67 return( TRUE);
68} 68}
@@ -123,34 +123,3 @@ int find_main(int argc, char **argv)
123 dirAction( directory, NULL); 123 dirAction( directory, NULL);
124 exit(TRUE); 124 exit(TRUE);
125} 125}
126
127
128
129#ifdef foobar
130
131#include "internal.h"
132#include <errno.h>
133#include <stdio.h>
134
135const char find_usage[] = "find dir [pattern]\n"
136"\n"
137"\tFind files.\n";
138
139extern int
140find_main(struct FileInfo * i, int argc, char * * argv)
141{
142 i->recursive=1;
143 i->processDirectoriesAfterTheirContents=1;
144 return monadic_main(i, argc, argv);
145}
146
147extern int
148find_fn(const struct FileInfo * i)
149{
150 printf("%s\n",i->source);
151
152 return(0);
153}
154
155
156#endif
diff --git a/findutils/find.c b/findutils/find.c
index c92202b86..1fb219496 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -62,7 +62,7 @@ static int dirAction(const char *fileName, struct stat* statbuf)
62 while ((entry = readdir(dir)) != NULL) { 62 while ((entry = readdir(dir)) != NULL) {
63 char dirName[NAME_MAX]; 63 char dirName[NAME_MAX];
64 sprintf(dirName, "%s/%s", fileName, entry->d_name); 64 sprintf(dirName, "%s/%s", fileName, entry->d_name);
65 recursiveAction( dirName, TRUE, dereferenceFlag, fileAction, dirAction); 65 recursiveAction( dirName, TRUE, dereferenceFlag, FALSE, fileAction, dirAction);
66 } 66 }
67 return( TRUE); 67 return( TRUE);
68} 68}
@@ -123,34 +123,3 @@ int find_main(int argc, char **argv)
123 dirAction( directory, NULL); 123 dirAction( directory, NULL);
124 exit(TRUE); 124 exit(TRUE);
125} 125}
126
127
128
129#ifdef foobar
130
131#include "internal.h"
132#include <errno.h>
133#include <stdio.h>
134
135const char find_usage[] = "find dir [pattern]\n"
136"\n"
137"\tFind files.\n";
138
139extern int
140find_main(struct FileInfo * i, int argc, char * * argv)
141{
142 i->recursive=1;
143 i->processDirectoriesAfterTheirContents=1;
144 return monadic_main(i, argc, argv);
145}
146
147extern int
148find_fn(const struct FileInfo * i)
149{
150 printf("%s\n",i->source);
151
152 return(0);
153}
154
155
156#endif
diff --git a/internal.h b/internal.h
index 4650e9f41..a87653927 100644
--- a/internal.h
+++ b/internal.h
@@ -121,7 +121,7 @@ char *chunkstrdup(const char *str);
121void freeChunks(void); 121void freeChunks(void);
122int fullWrite(int fd, const char *buf, int len); 122int fullWrite(int fd, const char *buf, int len);
123int fullRead(int fd, char *buf, int len); 123int fullRead(int fd, char *buf, int len);
124int recursiveAction(const char *fileName, int recurse, int followLinks, 124int recursiveAction(const char *fileName, int recurse, int followLinks, int delayDirAction,
125 int (*fileAction) (const char *fileName, struct stat* statbuf), 125 int (*fileAction) (const char *fileName, struct stat* statbuf),
126 int (*dirAction) (const char *fileName, struct stat* statbuf)); 126 int (*dirAction) (const char *fileName, struct stat* statbuf));
127int match(const char* text, const char * pattern); 127int match(const char* text, const char * pattern);
diff --git a/ls.c b/ls.c
index 50b983e24..2e3d50e9f 100644
--- a/ls.c
+++ b/ls.c
@@ -68,7 +68,7 @@ static int dirAction(const char *fileName)
68 exit(FALSE); 68 exit(FALSE);
69 } 69 }
70 while ((entry = readdir(dir)) != NULL) { 70 while ((entry = readdir(dir)) != NULL) {
71 recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, fileAction, dirAction); 71 recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, FALSE, fileAction, dirAction);
72 } 72 }
73 return( TRUE); 73 return( TRUE);
74} 74}
diff --git a/mv.c b/mv.c
index 10a082210..2a7c8c1f3 100644
--- a/mv.c
+++ b/mv.c
@@ -21,63 +21,59 @@
21 21
22#include "internal.h" 22#include "internal.h"
23#include <stdio.h> 23#include <stdio.h>
24#include <sys/types.h> 24#include <time.h>
25#include <sys/stat.h>
26#include <fcntl.h>
27#include <utime.h> 25#include <utime.h>
28#include <errno.h> 26#include <dirent.h>
29 27
30const char mv_usage[] = "source-file [source-file ...] destination-file\n"
31 "\n" "\tMove the source files to the destination.\n" "\n";
32 28
29static const char mv_usage[] = "mv SOURCE DEST\n"
30" or: mv SOURCE... DIRECTORY\n"
31"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
33 32
34 33
35extern int mv_main (int argc, char **argv) 34static const char *srcName;
35static const char *destName;
36static const char *skipName;
37static int dirFlag = FALSE;
38
39
40extern int mv_main(int argc, char **argv)
36{ 41{
37 const char *srcName; 42 char newdestName[NAME_MAX];
38 const char *destName;
39 const char *lastArg;
40 int dirFlag;
41 43
42 if (argc < 3) { 44 if (argc < 3) {
43 fprintf (stderr, "Usage: %s %s", *argv, mv_usage); 45 fprintf(stderr, "Usage: %s", mv_usage);
44 exit (FALSE); 46 exit (FALSE);
45 } 47 }
46 lastArg = argv[argc - 1]; 48 argc--;
49 argv++;
47 50
48 dirFlag = isDirectory (lastArg); 51 destName = argv[argc - 1];
52 dirFlag = isDirectory(destName);
49 53
50 if ((argc > 3) && !dirFlag) { 54 if ((argc > 3) && dirFlag==FALSE) {
51 fprintf (stderr, "%s: not a directory\n", lastArg); 55 fprintf(stderr, "%s: not a directory\n", destName);
52 exit (FALSE); 56 exit (FALSE);
53 } 57 }
54 58
55 while (argc-- > 2) { 59 while (argc-- > 1) {
56 srcName = *(++argv); 60 srcName = *(argv++);
57 61 skipName = strrchr(srcName, '/');
58 if (access (srcName, 0) < 0) { 62 if (skipName)
59 perror (srcName); 63 skipName++;
60 continue; 64 strcpy(newdestName, destName);
65 if (dirFlag==TRUE) {
66 strcat(newdestName, "/");
67 if ( skipName != NULL)
68 strcat(newdestName, strstr(srcName, skipName));
61 } 69 }
62 70 if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
63 destName = lastArg; 71 exit( FALSE);
64
65 if (dirFlag==TRUE)
66 destName = buildName (destName, srcName);
67
68 if (rename (srcName, destName) >= 0)
69 continue;
70
71 if (errno != EXDEV) {
72 perror (destName);
73 continue;
74 } 72 }
75 73 if (unlink (srcName) < 0) {
76 if (!copyFile (srcName, destName, TRUE, FALSE))
77 continue;
78
79 if (unlink (srcName) < 0)
80 perror (srcName); 74 perror (srcName);
75 exit( FALSE);
76 }
81 } 77 }
82 exit (TRUE); 78 exit( TRUE);
83} 79}
diff --git a/rm.c b/rm.c
index dc35b0297..477d3af59 100644
--- a/rm.c
+++ b/rm.c
@@ -1,30 +1,93 @@
1/*
2 * Mini rm implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1#include "internal.h" 22#include "internal.h"
2#include <errno.h> 23#include <stdio.h>
24#include <time.h>
25#include <utime.h>
26#include <dirent.h>
27
28static const char* rm_usage = "Usage: rm [OPTION]... FILE...\n"
29"Remove (unlink) the FILE(s).\n\n"
30"\t-f\tremove existing destinations, never prompt\n"
31"\t-r\tremove the contents of directories recursively\n";
32
33
34static int recursiveFlag = FALSE;
35static int forceFlag = FALSE;
36static const char *srcName;
37
3 38
4const char rm_usage[] = "rm [-r] file [file ...]\n" 39static int fileAction(const char *fileName, struct stat* statbuf)
5"\n" 40{
6"\tDelete files.\n" 41 if (unlink( fileName) < 0 ) {
7"\n" 42 perror( fileName);
8"\t-r:\tRecursively remove files and directories.\n"; 43 return ( FALSE);
44 }
45 return ( TRUE);
46}
9 47
10extern int 48static int dirAction(const char *fileName, struct stat* statbuf)
11rm_main(struct FileInfo * i, int argc, char * * argv)
12{ 49{
13 i->processDirectoriesAfterTheirContents = 1; 50 if (rmdir( fileName) < 0 ) {
14 return monadic_main(i, argc, argv); 51 perror( fileName);
52 return ( FALSE);
53 }
54 return ( TRUE);
15} 55}
16 56
17extern int 57extern int rm_main(int argc, char **argv)
18rm_fn(const struct FileInfo * i)
19{ 58{
20 if ( i->recursive 59
21 && !i->isSymbolicLink 60 if (argc < 2) {
22 && (i->stat.st_mode & S_IFMT) == S_IFDIR ) 61 fprintf(stderr, "Usage: %s", rm_usage);
23 return rmdir_fn(i); 62 exit (FALSE);
24 else if ( unlink(i->source) != 0 && errno != ENOENT && !i->force ) { 63 }
25 name_and_error(i->source); 64 argc--;
26 return 1; 65 argv++;
66
67 /* Parse any options */
68 while (**argv == '-') {
69 while (*++(*argv))
70 switch (**argv) {
71 case 'r':
72 recursiveFlag = TRUE;
73 break;
74 case 'f':
75 forceFlag = TRUE;
76 break;
77 default:
78 fprintf(stderr, "Usage: %s\n", rm_usage);
79 exit(FALSE);
80 }
81 argc--;
82 argv++;
83 }
84
85 while (argc-- > 0) {
86 srcName = *(argv++);
87 if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
88 fileAction, dirAction) == FALSE) {
89 exit( FALSE);
27 } 90 }
28 else 91 }
29 return 0; 92 exit( TRUE);
30} 93}
diff --git a/swapoff.c b/swapoff.c
index 55124d0b8..29b9daedd 100644
--- a/swapoff.c
+++ b/swapoff.c
@@ -13,7 +13,7 @@ swapoff_fn(const struct FileInfo * i)
13{ 13{
14 struct mntent entries[100]; 14 struct mntent entries[100];
15 int count = 0; 15 int count = 0;
16 FILE * swapsTable = setmntent("/etc/swaps", "r"); 16 FILE * swapsTable = setmntent("/proc/swaps", "r");
17 struct mntent * m; 17 struct mntent * m;
18 18
19 if (!(swapoff(i->source))) { 19 if (!(swapoff(i->source))) {
diff --git a/sync.c b/sync.c
index 6fa5b380b..e7aa44585 100644
--- a/sync.c
+++ b/sync.c
@@ -1,11 +1,12 @@
1#include "internal.h" 1#include "internal.h"
2 2
3const char sync_usage[] = "sync\n"
4"\n"
5"\tWrite all buffered filesystem blocks to disk.\n";
6
7extern int 3extern int
8sync_main(struct FileInfo * i, int argc, char * * argv) 4sync_main(int argc, char * * argv)
9{ 5{
6 if ( **(argv+1) == '-' ) {
7 fprintf(stderr, "Usage: sync\nWrite all buffered filesystem blocks to disk.\n");
8 exit(FALSE);
9 }
10 return sync(); 10 return sync();
11} 11}
12
diff --git a/umount.c b/umount.c
index 04cd8a080..a83a508f7 100644
--- a/umount.c
+++ b/umount.c
@@ -26,8 +26,11 @@
26#include <fstab.h> 26#include <fstab.h>
27#include <errno.h> 27#include <errno.h>
28 28
29const char umount_usage[] = "\tumount {filesystem|directory}\n" 29const char umount_usage[] =
30"or to unmount all mounted file systems:\n\tumount -a\n"; 30"Usage: umount filesystem\n"
31" or: umount directory\n"
32" or: umount -a"
33"to unmount all mounted file systems.\n";
31 34
32static int 35static int
33umount_all() 36umount_all()
diff --git a/util-linux/umount.c b/util-linux/umount.c
index 04cd8a080..a83a508f7 100644
--- a/util-linux/umount.c
+++ b/util-linux/umount.c
@@ -26,8 +26,11 @@
26#include <fstab.h> 26#include <fstab.h>
27#include <errno.h> 27#include <errno.h>
28 28
29const char umount_usage[] = "\tumount {filesystem|directory}\n" 29const char umount_usage[] =
30"or to unmount all mounted file systems:\n\tumount -a\n"; 30"Usage: umount filesystem\n"
31" or: umount directory\n"
32" or: umount -a"
33"to unmount all mounted file systems.\n";
31 34
32static int 35static int
33umount_all() 36umount_all()
diff --git a/utility.c b/utility.c
index 4bb479f0c..c6121cb11 100644
--- a/utility.c
+++ b/utility.c
@@ -188,36 +188,8 @@ copyFile( const char *srcName, const char *destName,
188#endif 188#endif
189 189
190 190
191#ifdef BB_MV
192/*
193 * Build a path name from the specified directory name and file name.
194 * If the directory name is NULL, then the original fileName is returned.
195 * The built path is in a static area, and is overwritten for each call.
196 */
197char *buildName(const char *dirName, const char *fileName)
198{
199 const char *cp;
200 static char buf[PATH_LEN];
201
202 if ((dirName == NULL) || (*dirName == '\0')) {
203 strcpy(buf, fileName);
204 return buf;
205 }
206
207 cp = strrchr(fileName, '/');
208
209 if (cp)
210 fileName = cp + 1;
211
212 strcpy(buf, dirName);
213 strcat(buf, "/");
214
215 return buf;
216}
217#endif
218
219
220 191
192#ifdef BB_TAR
221/* 193/*
222 * Return the standard ls-like mode string from a file mode. 194 * Return the standard ls-like mode string from a file mode.
223 * This is static and so is overwritten on each call. 195 * This is static and so is overwritten on each call.
@@ -239,15 +211,10 @@ const char *modeString(int mode)
239 buf[0] = 'b'; 211 buf[0] = 'b';
240 if (S_ISFIFO(mode)) 212 if (S_ISFIFO(mode))
241 buf[0] = 'p'; 213 buf[0] = 'p';
242#ifdef S_ISLNK
243 if (S_ISLNK(mode)) 214 if (S_ISLNK(mode))
244 buf[0] = 'l'; 215 buf[0] = 'l';
245#endif
246#ifdef S_ISSOCK
247 if (S_ISSOCK(mode)) 216 if (S_ISSOCK(mode))
248 buf[0] = 's'; 217 buf[0] = 's';
249#endif
250
251 /* 218 /*
252 * Now fill in the normal file permissions. 219 * Now fill in the normal file permissions.
253 */ 220 */
@@ -284,7 +251,6 @@ const char *modeString(int mode)
284} 251}
285 252
286 253
287#ifdef BB_TAR
288/* 254/*
289 * Get the time string to be used for a file. 255 * Get the time string to be used for a file.
290 * This is down to the minute for new files, but only the date for old files. 256 * This is down to the minute for new files, but only the date for old files.
@@ -467,7 +433,7 @@ int fullRead(int fd, char *buf, int len)
467 * by the fileAction and dirAction function pointers). 433 * by the fileAction and dirAction function pointers).
468 */ 434 */
469int 435int
470recursiveAction(const char *fileName, int recurse, int followLinks, 436recursiveAction(const char *fileName, int recurse, int followLinks, int delayDirAction,
471 int (*fileAction) (const char *fileName, struct stat* statbuf), 437 int (*fileAction) (const char *fileName, struct stat* statbuf),
472 int (*dirAction) (const char *fileName, struct stat* statbuf)) 438 int (*dirAction) (const char *fileName, struct stat* statbuf))
473{ 439{
@@ -501,7 +467,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
501 perror(fileName); 467 perror(fileName);
502 return (FALSE); 468 return (FALSE);
503 } 469 }
504 if (dirAction != NULL) { 470 if (dirAction != NULL && delayDirAction == FALSE) {
505 status = dirAction(fileName, &statbuf); 471 status = dirAction(fileName, &statbuf);
506 if (status == FALSE) { 472 if (status == FALSE) {
507 perror(fileName); 473 perror(fileName);
@@ -516,8 +482,8 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
516 } 482 }
517 sprintf(nextFile, "%s/%s", fileName, next->d_name); 483 sprintf(nextFile, "%s/%s", fileName, next->d_name);
518 status = 484 status =
519 recursiveAction(nextFile, TRUE, followLinks, fileAction, 485 recursiveAction(nextFile, TRUE, followLinks, delayDirAction,
520 dirAction); 486 fileAction, dirAction);
521 if (status < 0) { 487 if (status < 0) {
522 closedir(dir); 488 closedir(dir);
523 return (FALSE); 489 return (FALSE);
@@ -528,6 +494,13 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
528 perror(fileName); 494 perror(fileName);
529 return (FALSE); 495 return (FALSE);
530 } 496 }
497 if (dirAction != NULL && delayDirAction == TRUE) {
498 status = dirAction(fileName, &statbuf);
499 if (status == FALSE) {
500 perror(fileName);
501 return (FALSE);
502 }
503 }
531 } else { 504 } else {
532 if (fileAction == NULL) 505 if (fileAction == NULL)
533 return (TRUE); 506 return (TRUE);