aboutsummaryrefslogtreecommitdiff
path: root/rm.c
diff options
context:
space:
mode:
Diffstat (limited to 'rm.c')
-rw-r--r--rm.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/rm.c b/rm.c
index c62d68aba..5901c5da9 100644
--- a/rm.c
+++ b/rm.c
@@ -31,7 +31,8 @@
31 31
32static const char *rm_usage = "rm [OPTION]... FILE...\n" 32static const char *rm_usage = "rm [OPTION]... FILE...\n"
33#ifndef BB_FEATURE_TRIVIAL_HELP 33#ifndef BB_FEATURE_TRIVIAL_HELP
34 "\nRemove (unlink) the FILE(s).\n\n" 34 "\nRemove (unlink) the FILE(s). You may use '--' to\n"
35 "indicate that all following arguments are non-options.\n\n"
35 "Options:\n" 36 "Options:\n"
36 "\t-f\t\tremove existing destinations, never prompt\n" 37 "\t-f\t\tremove existing destinations, never prompt\n"
37 "\t-r or -R\tremove the contents of directories recursively\n" 38 "\t-r or -R\tremove the contents of directories recursively\n"
@@ -64,29 +65,33 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
64 65
65extern int rm_main(int argc, char **argv) 66extern int rm_main(int argc, char **argv)
66{ 67{
68 int stopIt=FALSE;
67 struct stat statbuf; 69 struct stat statbuf;
68 70
69 if (argc < 2) { 71 if (argc < 2) {
70 usage(rm_usage); 72 usage(rm_usage);
71 } 73 }
72 argc--;
73 argv++; 74 argv++;
74 75
75 /* Parse any options */ 76 /* Parse any options */
76 while (**argv == '-') { 77 while (--argc >= 0 && *argv && **argv && stopIt==FALSE) {
77 while (*++(*argv)) 78 while (**argv == '-') {
78 switch (**argv) { 79 while (*++(*argv))
79 case 'R': 80 switch (**argv) {
80 case 'r': 81 case 'R':
81 recursiveFlag = TRUE; 82 case 'r':
82 break; 83 recursiveFlag = TRUE;
83 case 'f': 84 break;
84 forceFlag = TRUE; 85 case 'f':
85 break; 86 forceFlag = TRUE;
86 default: 87 break;
87 usage(rm_usage); 88 case '-':
88 } 89 stopIt = TRUE;
89 argc--; 90 break;
91 default:
92 usage(rm_usage);
93 }
94 }
90 argv++; 95 argv++;
91 } 96 }
92 97