aboutsummaryrefslogtreecommitdiff
path: root/rm.c
diff options
context:
space:
mode:
authorerik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277>2000-02-08 19:58:47 +0000
committererik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277>2000-02-08 19:58:47 +0000
commita18125005d67c38a8ad7fb454571bb996664ad96 (patch)
treec90bda10731ad9333ce3b404f993354c9fc104b8 /rm.c
parent8ef3b44285a8ce5b83bed9cf32ce5f40b30ba72f (diff)
downloadbusybox-w32-a18125005d67c38a8ad7fb454571bb996664ad96.tar.gz
busybox-w32-a18125005d67c38a8ad7fb454571bb996664ad96.tar.bz2
busybox-w32-a18125005d67c38a8ad7fb454571bb996664ad96.zip
Some formatting updates (ran the code through indent)
-Erik git-svn-id: svn://busybox.net/trunk/busybox@357 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'rm.c')
-rw-r--r--rm.c102
1 files changed, 52 insertions, 50 deletions
diff --git a/rm.c b/rm.c
index ee434fb39..41afedaf9 100644
--- a/rm.c
+++ b/rm.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini rm implementation for busybox 3 * Mini rm implementation for busybox
3 * 4 *
@@ -28,11 +29,12 @@
28#include <dirent.h> 29#include <dirent.h>
29#include <errno.h> 30#include <errno.h>
30 31
31static const char* rm_usage = "rm [OPTION]... FILE...\n\n" 32static const char *rm_usage = "rm [OPTION]... FILE...\n\n"
32"Remove (unlink) the FILE(s).\n\n" 33 "Remove (unlink) the FILE(s).\n\n"
33"Options:\n" 34 "Options:\n"
34"\t-f\t\tremove existing destinations, never prompt\n" 35
35"\t-r or -R\tremove the contents of directories recursively\n"; 36 "\t-f\t\tremove existing destinations, never prompt\n"
37 "\t-r or -R\tremove the contents of directories recursively\n";
36 38
37 39
38static int recursiveFlag = FALSE; 40static int recursiveFlag = FALSE;
@@ -40,63 +42,63 @@ static int forceFlag = FALSE;
40static const char *srcName; 42static const char *srcName;
41 43
42 44
43static int fileAction(const char *fileName, struct stat* statbuf) 45static int fileAction(const char *fileName, struct stat *statbuf)
44{ 46{
45 if (unlink( fileName) < 0 ) { 47 if (unlink(fileName) < 0) {
46 perror( fileName); 48 perror(fileName);
47 return ( FALSE); 49 return (FALSE);
48 } 50 }
49 return ( TRUE); 51 return (TRUE);
50} 52}
51 53
52static int dirAction(const char *fileName, struct stat* statbuf) 54static int dirAction(const char *fileName, struct stat *statbuf)
53{ 55{
54 if (rmdir( fileName) < 0 ) { 56 if (rmdir(fileName) < 0) {
55 perror( fileName); 57 perror(fileName);
56 return ( FALSE); 58 return (FALSE);
57 } 59 }
58 return ( TRUE); 60 return (TRUE);
59} 61}
60 62
61extern int rm_main(int argc, char **argv) 63extern int rm_main(int argc, char **argv)
62{ 64{
63 struct stat statbuf; 65 struct stat statbuf;
64 66
65 if (argc < 2) { 67 if (argc < 2) {
66 usage( rm_usage); 68 usage(rm_usage);
67 } 69 }
68 argc--;
69 argv++;
70
71 /* Parse any options */
72 while (**argv == '-') {
73 while (*++(*argv))
74 switch (**argv) {
75 case 'R':
76 case 'r':
77 recursiveFlag = TRUE;
78 break;
79 case 'f':
80 forceFlag = TRUE;
81 break;
82 default:
83 usage( rm_usage);
84 }
85 argc--; 70 argc--;
86 argv++; 71 argv++;
87 }
88 72
89 while (argc-- > 0) { 73 /* Parse any options */
90 srcName = *(argv++); 74 while (**argv == '-') {
91 if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0 && errno == ENOENT) { 75 while (*++(*argv))
92 /* do not reports errors for non-existent files if -f, just skip them */ 76 switch (**argv) {
77 case 'R':
78 case 'r':
79 recursiveFlag = TRUE;
80 break;
81 case 'f':
82 forceFlag = TRUE;
83 break;
84 default:
85 usage(rm_usage);
86 }
87 argc--;
88 argv++;
93 } 89 }
94 else { 90
95 if (recursiveAction( srcName, recursiveFlag, FALSE, 91 while (argc-- > 0) {
96 TRUE, fileAction, dirAction) == FALSE) { 92 srcName = *(argv++);
97 exit( FALSE); 93 if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0
98 } 94 && errno == ENOENT) {
95 /* do not reports errors for non-existent files if -f, just skip them */
96 } else {
97 if (recursiveAction(srcName, recursiveFlag, FALSE,
98 TRUE, fileAction, dirAction) == FALSE) {
99 exit(FALSE);
100 }
101 }
99 } 102 }
100 } 103 exit(TRUE);
101 exit( TRUE);
102} 104}