diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-04-08 10:52:28 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-04-08 10:52:28 +0000 |
commit | 2f52663264c7c37d578e72f532f01b9fd9cd7ebc (patch) | |
tree | 98df39594da2e7f1fbe560aec04eeb09426947f0 | |
parent | 1b3f1d1383f39b07eac82cafadab811e7a21d96c (diff) | |
download | busybox-w32-2f52663264c7c37d578e72f532f01b9fd9cd7ebc.tar.gz busybox-w32-2f52663264c7c37d578e72f532f01b9fd9cd7ebc.tar.bz2 busybox-w32-2f52663264c7c37d578e72f532f01b9fd9cd7ebc.zip |
find: fix handling of -prune
recursive_actions: uppercase flag constants
git-svn-id: svn://busybox.net/trunk/busybox@18362 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | archival/tar.c | 4 | ||||
-rw-r--r-- | coreutils/chown.c | 4 | ||||
-rw-r--r-- | coreutils/diff.c | 2 | ||||
-rw-r--r-- | debianutils/run_parts.c | 2 | ||||
-rw-r--r-- | findutils/find.c | 68 | ||||
-rw-r--r-- | findutils/grep.c | 6 | ||||
-rw-r--r-- | include/libbb.h | 26 | ||||
-rw-r--r-- | libbb/recursive_action.c | 14 | ||||
-rw-r--r-- | modutils/insmod.c | 4 |
9 files changed, 71 insertions, 59 deletions
diff --git a/archival/tar.c b/archival/tar.c index 5a6ef60db..6552d6c57 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -562,8 +562,8 @@ static int writeTarFile(const int tar_fd, const int verboseFlag, | |||
562 | 562 | ||
563 | /* Read the directory/files and iterate over them one at a time */ | 563 | /* Read the directory/files and iterate over them one at a time */ |
564 | while (include) { | 564 | while (include) { |
565 | if (!recursive_action(include->data, (action_recurse | | 565 | if (!recursive_action(include->data, ACTION_RECURSE | |
566 | dereferenceFlag ? action_followLinks : 0), | 566 | (dereferenceFlag ? ACTION_FOLLOWLINKS : 0), |
567 | writeFileToTarball, writeFileToTarball, &tbInfo, 0)) | 567 | writeFileToTarball, writeFileToTarball, &tbInfo, 0)) |
568 | { | 568 | { |
569 | errorFlag = TRUE; | 569 | errorFlag = TRUE; |
diff --git a/coreutils/chown.c b/coreutils/chown.c index 09b1a595b..e64a39c3e 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c | |||
@@ -92,8 +92,8 @@ int chown_main(int argc, char **argv) | |||
92 | } | 92 | } |
93 | 93 | ||
94 | if (!recursive_action(arg, | 94 | if (!recursive_action(arg, |
95 | (OPT_RECURSE ? action_recurse : 0 | /* recurse */ | 95 | (OPT_RECURSE ? ACTION_RECURSE : 0) | /* recurse */ |
96 | OPT_TRAVERSE ? action_followLinks : 0),/* follow links if -L */ | 96 | (OPT_TRAVERSE ? ACTION_FOLLOWLINKS : 0),/* follow links if -L */ |
97 | fileAction, /* file action */ | 97 | fileAction, /* file action */ |
98 | fileAction, /* dir action */ | 98 | fileAction, /* dir action */ |
99 | chown_func, /* user data */ | 99 | chown_func, /* user data */ |
diff --git a/coreutils/diff.c b/coreutils/diff.c index 75557187c..09cacbde6 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c | |||
@@ -1079,7 +1079,7 @@ static char **get_dir(char *path) | |||
1079 | * add_to_dirlist then removes root dir prefix. */ | 1079 | * add_to_dirlist then removes root dir prefix. */ |
1080 | 1080 | ||
1081 | if (option_mask32 & FLAG_r) { | 1081 | if (option_mask32 & FLAG_r) { |
1082 | recursive_action(path, action_recurse|action_followLinks, | 1082 | recursive_action(path, ACTION_RECURSE|ACTION_FOLLOWLINKS, |
1083 | add_to_dirlist, NULL, | 1083 | add_to_dirlist, NULL, |
1084 | (void*)(strlen(path)+1), 0); | 1084 | (void*)(strlen(path)+1), 0); |
1085 | } else { | 1085 | } else { |
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index c67072730..873263a22 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c | |||
@@ -138,7 +138,7 @@ int run_parts_main(int argc, char **argv) | |||
138 | G.cmd[tmp] = arg_list->data; | 138 | G.cmd[tmp] = arg_list->data; |
139 | /* G.cmd[tmp] = NULL; - G is already zeroed out */ | 139 | /* G.cmd[tmp] = NULL; - G is already zeroed out */ |
140 | if (!recursive_action(argv[argc - 1], | 140 | if (!recursive_action(argv[argc - 1], |
141 | action_recurse|action_followLinks, | 141 | ACTION_RECURSE|ACTION_FOLLOWLINKS, |
142 | act, /* file action */ | 142 | act, /* file action */ |
143 | act, /* dir action */ | 143 | act, /* dir action */ |
144 | NULL, /* user data */ | 144 | NULL, /* user data */ |
diff --git a/findutils/find.c b/findutils/find.c index 43120250b..3eea53db0 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -70,7 +70,7 @@ USE_FEATURE_FIND_MTIME( ACTS(mtime, char mtime_char; unsigned mtime_days;)) | |||
70 | USE_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; unsigned mmin_mins;)) | 70 | USE_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; unsigned mmin_mins;)) |
71 | USE_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;)) | 71 | USE_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;)) |
72 | USE_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;)) | 72 | USE_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;)) |
73 | USE_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned int *subst_count; int exec_argc;)) | 73 | USE_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;)) |
74 | USE_FEATURE_FIND_USER( ACTS(user, uid_t uid;)) | 74 | USE_FEATURE_FIND_USER( ACTS(user, uid_t uid;)) |
75 | USE_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;)) | 75 | USE_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;)) |
76 | USE_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;)) | 76 | USE_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;)) |
@@ -79,12 +79,12 @@ USE_FEATURE_FIND_PRUNE( ACTS(prune)) | |||
79 | 79 | ||
80 | static action ***actions; | 80 | static action ***actions; |
81 | static bool need_print = 1; | 81 | static bool need_print = 1; |
82 | static int recurse_flags = action_recurse; | 82 | static int recurse_flags = ACTION_RECURSE; |
83 | 83 | ||
84 | #if ENABLE_FEATURE_FIND_EXEC | 84 | #if ENABLE_FEATURE_FIND_EXEC |
85 | static unsigned int count_subst(const char *str) | 85 | static unsigned count_subst(const char *str) |
86 | { | 86 | { |
87 | unsigned int count = 0; | 87 | unsigned count = 0; |
88 | while ((str = strstr(str, "{}"))) { | 88 | while ((str = strstr(str, "{}"))) { |
89 | count++; | 89 | count++; |
90 | str++; | 90 | str++; |
@@ -93,7 +93,7 @@ static unsigned int count_subst(const char *str) | |||
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | static char* subst(const char *src, unsigned int count, const char* filename) | 96 | static char* subst(const char *src, unsigned count, const char* filename) |
97 | { | 97 | { |
98 | char *buf, *dst, *end; | 98 | char *buf, *dst, *end; |
99 | size_t flen = strlen(filename); | 99 | size_t flen = strlen(filename); |
@@ -111,6 +111,10 @@ static char* subst(const char *src, unsigned int count, const char* filename) | |||
111 | } | 111 | } |
112 | #endif | 112 | #endif |
113 | 113 | ||
114 | /* Return values of ACTFs ('action functions') are a bit mask: | ||
115 | * bit 1=1: prune (use SKIP constant for setting it) | ||
116 | * bit 0=1: matched successfully (TRUE) | ||
117 | */ | ||
114 | 118 | ||
115 | static int exec_actions(action ***appp, const char *fileName, struct stat *statbuf) | 119 | static int exec_actions(action ***appp, const char *fileName, struct stat *statbuf) |
116 | { | 120 | { |
@@ -121,24 +125,24 @@ static int exec_actions(action ***appp, const char *fileName, struct stat *statb | |||
121 | 125 | ||
122 | cur_group = -1; | 126 | cur_group = -1; |
123 | while ((app = appp[++cur_group])) { | 127 | while ((app = appp[++cur_group])) { |
128 | /* We invert TRUE bit (bit 0). Now 1 there means 'failure'. | ||
129 | * and bitwise OR in "rc |= TRUE ^ ap->f()" will: | ||
130 | * (1) make SKIP bit stick; and (2) detect 'failure' */ | ||
131 | rc = 0; /* 'success' so far */ | ||
124 | cur_action = -1; | 132 | cur_action = -1; |
125 | while (1) { | 133 | while (1) { |
126 | ap = app[++cur_action]; | 134 | ap = app[++cur_action]; |
127 | if (!ap) { | 135 | if (!ap) /* all actions in group were successful */ |
128 | /* all actions in group were successful */ | 136 | return rc ^ TRUE; |
129 | return rc; | 137 | rc |= TRUE ^ ap->f(fileName, statbuf, ap); |
130 | } | ||
131 | rc = ap->f(fileName, statbuf, ap); | ||
132 | #if ENABLE_FEATURE_FIND_NOT | 138 | #if ENABLE_FEATURE_FIND_NOT |
133 | if (ap->invert) rc = !rc; | 139 | if (ap->invert) rc ^= TRUE; |
134 | #endif | 140 | #endif |
135 | if (!rc) { | 141 | if (rc & TRUE) /* current group failed, try next */ |
136 | /* current group failed, try next */ | ||
137 | break; | 142 | break; |
138 | } | ||
139 | } | 143 | } |
140 | } | 144 | } |
141 | return rc; | 145 | return rc ^ TRUE; /* straighten things out */ |
142 | } | 146 | } |
143 | 147 | ||
144 | 148 | ||
@@ -147,8 +151,16 @@ ACTF(name) | |||
147 | const char *tmp = strrchr(fileName, '/'); | 151 | const char *tmp = strrchr(fileName, '/'); |
148 | if (tmp == NULL) | 152 | if (tmp == NULL) |
149 | tmp = fileName; | 153 | tmp = fileName; |
150 | else | 154 | else { |
151 | tmp++; | 155 | tmp++; |
156 | if (!*tmp) { /* "foo/bar/". Oh no... go back to 'b' */ | ||
157 | tmp--; | ||
158 | while (tmp != fileName && *--tmp != '/') | ||
159 | continue; | ||
160 | if (*tmp == '/') | ||
161 | tmp++; | ||
162 | } | ||
163 | } | ||
152 | return fnmatch(ap->pattern, tmp, FNM_PERIOD) == 0; | 164 | return fnmatch(ap->pattern, tmp, FNM_PERIOD) == 0; |
153 | } | 165 | } |
154 | #if ENABLE_FEATURE_FIND_TYPE | 166 | #if ENABLE_FEATURE_FIND_TYPE |
@@ -269,7 +281,7 @@ ACTF(paren) | |||
269 | */ | 281 | */ |
270 | ACTF(prune) | 282 | ACTF(prune) |
271 | { | 283 | { |
272 | return SKIP; | 284 | return SKIP + TRUE; |
273 | } | 285 | } |
274 | #endif | 286 | #endif |
275 | 287 | ||
@@ -284,7 +296,7 @@ ACTF(size) | |||
284 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk, int depth) | 296 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk, int depth) |
285 | { | 297 | { |
286 | int i; | 298 | int i; |
287 | #ifdef CONFIG_FEATURE_FIND_XDEV | 299 | #if ENABLE_FEATURE_FIND_XDEV |
288 | if (S_ISDIR(statbuf->st_mode) && xdev_count) { | 300 | if (S_ISDIR(statbuf->st_mode) && xdev_count) { |
289 | for (i = 0; i < xdev_count; i++) { | 301 | for (i = 0; i < xdev_count; i++) { |
290 | if (xdev_dev[i] != statbuf->st_dev) | 302 | if (xdev_dev[i] != statbuf->st_dev) |
@@ -294,11 +306,11 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk, in | |||
294 | #endif | 306 | #endif |
295 | i = exec_actions(actions, fileName, statbuf); | 307 | i = exec_actions(actions, fileName, statbuf); |
296 | /* Had no explicit -print[0] or -exec? then print */ | 308 | /* Had no explicit -print[0] or -exec? then print */ |
297 | if (i && need_print) | 309 | if ((i & TRUE) && need_print) |
298 | puts(fileName); | 310 | puts(fileName); |
299 | /* Cannot return 0: our caller, recursive_action(), | 311 | /* Cannot return 0: our caller, recursive_action(), |
300 | * will perror() and skip dirs (if called on dir) */ | 312 | * will perror() and skip dirs (if called on dir) */ |
301 | return i == 0 ? TRUE : i; | 313 | return (i & SKIP) ? SKIP : TRUE; |
302 | } | 314 | } |
303 | 315 | ||
304 | 316 | ||
@@ -386,8 +398,8 @@ static action*** parse_params(char **argv) | |||
386 | USE_FEATURE_FIND_GROUP( "-group" ,) | 398 | USE_FEATURE_FIND_GROUP( "-group" ,) |
387 | USE_FEATURE_FIND_DEPTH( "-depth" ,) | 399 | USE_FEATURE_FIND_DEPTH( "-depth" ,) |
388 | USE_FEATURE_FIND_PAREN( "(" ,) | 400 | USE_FEATURE_FIND_PAREN( "(" ,) |
389 | USE_FEATURE_FIND_SIZE( "-size" ,) | 401 | USE_FEATURE_FIND_SIZE( "-size" ,) |
390 | USE_FEATURE_FIND_PRUNE( "-prune" ,) | 402 | USE_FEATURE_FIND_PRUNE( "-prune" ,) |
391 | #if ENABLE_DESKTOP | 403 | #if ENABLE_DESKTOP |
392 | "-and" , | 404 | "-and" , |
393 | "-or" , | 405 | "-or" , |
@@ -486,8 +498,7 @@ static action*** parse_params(char **argv) | |||
486 | } | 498 | } |
487 | #endif | 499 | #endif |
488 | #if ENABLE_FEATURE_FIND_PERM | 500 | #if ENABLE_FEATURE_FIND_PERM |
489 | /* TODO: | 501 | /* -perm mode File's permission bits are exactly mode (octal or symbolic). |
490 | * -perm mode File's permission bits are exactly mode (octal or symbolic). | ||
491 | * Symbolic modes use mode 0 as a point of departure. | 502 | * Symbolic modes use mode 0 as a point of departure. |
492 | * -perm -mode All of the permission bits mode are set for the file. | 503 | * -perm -mode All of the permission bits mode are set for the file. |
493 | * -perm +mode Any of the permission bits mode are set for the file. | 504 | * -perm +mode Any of the permission bits mode are set for the file. |
@@ -554,7 +565,7 @@ static action*** parse_params(char **argv) | |||
554 | ap->exec_argv = ++argv; /* first arg after -exec */ | 565 | ap->exec_argv = ++argv; /* first arg after -exec */ |
555 | ap->exec_argc = 0; | 566 | ap->exec_argc = 0; |
556 | while (1) { | 567 | while (1) { |
557 | if (!*argv) /* did not see ';' util end */ | 568 | if (!*argv) /* did not see ';' until end */ |
558 | bb_error_msg_and_die(bb_msg_requires_arg, arg); | 569 | bb_error_msg_and_die(bb_msg_requires_arg, arg); |
559 | if (LONE_CHAR(argv[0], ';')) | 570 | if (LONE_CHAR(argv[0], ';')) |
560 | break; | 571 | break; |
@@ -593,7 +604,7 @@ static action*** parse_params(char **argv) | |||
593 | #endif | 604 | #endif |
594 | #if ENABLE_FEATURE_FIND_DEPTH | 605 | #if ENABLE_FEATURE_FIND_DEPTH |
595 | else if (parm == PARM_depth) { | 606 | else if (parm == PARM_depth) { |
596 | recurse_flags |= action_depthFirst; | 607 | recurse_flags |= ACTION_DEPTHFIRST; |
597 | } | 608 | } |
598 | #endif | 609 | #endif |
599 | #if ENABLE_FEATURE_FIND_PAREN | 610 | #if ENABLE_FEATURE_FIND_PAREN |
@@ -652,7 +663,6 @@ USE_FEATURE_FIND_XDEV( "-xdev", ) | |||
652 | NULL | 663 | NULL |
653 | }; | 664 | }; |
654 | 665 | ||
655 | bool dereference = FALSE; | ||
656 | char *arg; | 666 | char *arg; |
657 | char **argp; | 667 | char **argp; |
658 | int i, firstopt, status = EXIT_SUCCESS; | 668 | int i, firstopt, status = EXIT_SUCCESS; |
@@ -684,7 +694,7 @@ USE_FEATURE_FIND_XDEV( "-xdev", ) | |||
684 | while ((arg = argp[0])) { | 694 | while ((arg = argp[0])) { |
685 | i = index_in_str_array(options, arg); | 695 | i = index_in_str_array(options, arg); |
686 | if (i == 0) { /* -follow */ | 696 | if (i == 0) { /* -follow */ |
687 | dereference = TRUE; | 697 | recurse_flags |= ACTION_FOLLOWLINKS; |
688 | argp[0] = (char*)"-a"; | 698 | argp[0] = (char*)"-a"; |
689 | } | 699 | } |
690 | #if ENABLE_FEATURE_FIND_XDEV | 700 | #if ENABLE_FEATURE_FIND_XDEV |
@@ -711,7 +721,7 @@ USE_FEATURE_FIND_XDEV( "-xdev", ) | |||
711 | 721 | ||
712 | for (i = 1; i < firstopt; i++) { | 722 | for (i = 1; i < firstopt; i++) { |
713 | if (!recursive_action(argv[i], | 723 | if (!recursive_action(argv[i], |
714 | recurse_flags|(1<<dereference), /* flags */ | 724 | recurse_flags, /* flags */ |
715 | fileAction, /* file action */ | 725 | fileAction, /* file action */ |
716 | fileAction, /* dir action */ | 726 | fileAction, /* dir action */ |
717 | NULL, /* user data */ | 727 | NULL, /* user data */ |
diff --git a/findutils/grep.c b/findutils/grep.c index 370b753d7..2ca4a3a0a 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -336,9 +336,9 @@ static int grep_dir(const char *dir) | |||
336 | { | 336 | { |
337 | int matched = 0; | 337 | int matched = 0; |
338 | recursive_action(dir, | 338 | recursive_action(dir, |
339 | /* recurse= */ action_recurse | | 339 | /* recurse=yes */ ACTION_RECURSE | |
340 | /* followLinks= */ /* no. 0 | */ | 340 | /* followLinks=no */ |
341 | /* depthFirst= */ action_depthFirst, | 341 | /* depthFirst=yes */ ACTION_DEPTHFIRST, |
342 | /* fileAction= */ file_action_grep, | 342 | /* fileAction= */ file_action_grep, |
343 | /* dirAction= */ NULL, | 343 | /* dirAction= */ NULL, |
344 | /* userData= */ &matched, | 344 | /* userData= */ &matched, |
diff --git a/include/libbb.h b/include/libbb.h index 764d707b8..6956aaf7b 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -178,7 +178,7 @@ struct hwtype { | |||
178 | 178 | ||
179 | /* buffer allocation schemes */ | 179 | /* buffer allocation schemes */ |
180 | #if ENABLE_FEATURE_BUFFERS_GO_ON_STACK | 180 | #if ENABLE_FEATURE_BUFFERS_GO_ON_STACK |
181 | #define RESERVE_CONFIG_BUFFER(buffer,len) char buffer[len] | 181 | #define RESERVE_CONFIG_BUFFER(buffer,len) char buffer[len] |
182 | #define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char buffer[len] | 182 | #define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char buffer[len] |
183 | #define RELEASE_CONFIG_BUFFER(buffer) ((void)0) | 183 | #define RELEASE_CONFIG_BUFFER(buffer) ((void)0) |
184 | #else | 184 | #else |
@@ -187,9 +187,9 @@ struct hwtype { | |||
187 | #define RESERVE_CONFIG_UBUFFER(buffer,len) static unsigned char buffer[len] | 187 | #define RESERVE_CONFIG_UBUFFER(buffer,len) static unsigned char buffer[len] |
188 | #define RELEASE_CONFIG_BUFFER(buffer) ((void)0) | 188 | #define RELEASE_CONFIG_BUFFER(buffer) ((void)0) |
189 | #else | 189 | #else |
190 | #define RESERVE_CONFIG_BUFFER(buffer,len) char *buffer=xmalloc(len) | 190 | #define RESERVE_CONFIG_BUFFER(buffer,len) char *buffer = xmalloc(len) |
191 | #define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len) | 191 | #define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char *buffer = xmalloc(len) |
192 | #define RELEASE_CONFIG_BUFFER(buffer) free (buffer) | 192 | #define RELEASE_CONFIG_BUFFER(buffer) free(buffer) |
193 | #endif | 193 | #endif |
194 | #endif | 194 | #endif |
195 | 195 | ||
@@ -219,7 +219,7 @@ struct sysinfo { | |||
219 | unsigned int mem_unit; /* Memory unit size in bytes */ | 219 | unsigned int mem_unit; /* Memory unit size in bytes */ |
220 | char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ | 220 | char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ |
221 | }; | 221 | }; |
222 | extern int sysinfo(struct sysinfo* info); | 222 | int sysinfo(struct sysinfo* info); |
223 | 223 | ||
224 | 224 | ||
225 | extern void chomp(char *s); | 225 | extern void chomp(char *s); |
@@ -232,10 +232,12 @@ extern const char *bb_mode_string(mode_t mode); | |||
232 | extern int is_directory(const char *name, int followLinks, struct stat *statBuf); | 232 | extern int is_directory(const char *name, int followLinks, struct stat *statBuf); |
233 | extern int remove_file(const char *path, int flags); | 233 | extern int remove_file(const char *path, int flags); |
234 | extern int copy_file(const char *source, const char *dest, int flags); | 234 | extern int copy_file(const char *source, const char *dest, int flags); |
235 | #define action_recurse (1<<0) | 235 | enum { |
236 | #define action_followLinks (1<<1) | 236 | ACTION_RECURSE = (1 << 0), |
237 | #define action_depthFirst (1<<2) | 237 | ACTION_FOLLOWLINKS = (1 << 1), |
238 | #define action_reverse (1<<3) | 238 | ACTION_DEPTHFIRST = (1 << 2), |
239 | /*ACTION_REVERSE = (1 << 3), - unused */ | ||
240 | }; | ||
239 | extern int recursive_action(const char *fileName, unsigned flags, | 241 | extern int recursive_action(const char *fileName, unsigned flags, |
240 | int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData, int depth), | 242 | int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData, int depth), |
241 | int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData, int depth), | 243 | int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData, int depth), |
@@ -260,13 +262,12 @@ int ndelay_off(int fd); | |||
260 | void xmove_fd(int, int); | 262 | void xmove_fd(int, int); |
261 | 263 | ||
262 | 264 | ||
263 | extern DIR *xopendir(const char *path); | 265 | DIR *xopendir(const char *path); |
264 | extern DIR *warn_opendir(const char *path); | 266 | DIR *warn_opendir(const char *path); |
265 | 267 | ||
266 | char *xrealloc_getcwd_or_warn(char *cwd); | 268 | char *xrealloc_getcwd_or_warn(char *cwd); |
267 | char *xmalloc_readlink_or_warn(const char *path); | 269 | char *xmalloc_readlink_or_warn(const char *path); |
268 | char *xmalloc_realpath(const char *path); | 270 | char *xmalloc_realpath(const char *path); |
269 | extern void xstat(const char *filename, struct stat *buf); | ||
270 | 271 | ||
271 | /* Unlike waitpid, waits ONLY for one process, | 272 | /* Unlike waitpid, waits ONLY for one process, |
272 | * It's safe to pass negative 'pids' from failed [v]fork - | 273 | * It's safe to pass negative 'pids' from failed [v]fork - |
@@ -299,6 +300,7 @@ void xsetuid(uid_t uid); | |||
299 | void xchdir(const char *path); | 300 | void xchdir(const char *path); |
300 | void xsetenv(const char *key, const char *value); | 301 | void xsetenv(const char *key, const char *value); |
301 | void xunlink(const char *pathname); | 302 | void xunlink(const char *pathname); |
303 | void xstat(const char *pathname, struct stat *buf); | ||
302 | int xopen(const char *pathname, int flags); | 304 | int xopen(const char *pathname, int flags); |
303 | int xopen3(const char *pathname, int flags, int mode); | 305 | int xopen3(const char *pathname, int flags, int mode); |
304 | off_t xlseek(int fd, off_t offset, int whence); | 306 | off_t xlseek(int fd, off_t offset, int whence); |
diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c index 0c0531575..be2a700f5 100644 --- a/libbb/recursive_action.c +++ b/libbb/recursive_action.c | |||
@@ -55,12 +55,12 @@ int recursive_action(const char *fileName, | |||
55 | 55 | ||
56 | if (!fileAction) fileAction = true_action; | 56 | if (!fileAction) fileAction = true_action; |
57 | if (!dirAction) dirAction = true_action; | 57 | if (!dirAction) dirAction = true_action; |
58 | status = (flags & action_followLinks ? stat : lstat)(fileName, &statbuf); | 58 | status = (flags & ACTION_FOLLOWLINKS ? stat : lstat)(fileName, &statbuf); |
59 | 59 | ||
60 | if (status < 0) { | 60 | if (status < 0) { |
61 | #ifdef DEBUG_RECURS_ACTION | 61 | #ifdef DEBUG_RECURS_ACTION |
62 | bb_error_msg("status=%d followLinks=%d TRUE=%d", | 62 | bb_error_msg("status=%d followLinks=%d TRUE=%d", |
63 | status, flags & action_followLinks, TRUE); | 63 | status, flags & ACTION_FOLLOWLINKS, TRUE); |
64 | #endif | 64 | #endif |
65 | goto done_nak_warn; | 65 | goto done_nak_warn; |
66 | } | 66 | } |
@@ -68,7 +68,7 @@ int recursive_action(const char *fileName, | |||
68 | /* If S_ISLNK(m), then we know that !S_ISDIR(m). | 68 | /* If S_ISLNK(m), then we know that !S_ISDIR(m). |
69 | * Then we can skip checking first part: if it is true, then | 69 | * Then we can skip checking first part: if it is true, then |
70 | * (!dir) is also true! */ | 70 | * (!dir) is also true! */ |
71 | if ( /* (!(flags & action_followLinks) && S_ISLNK(statbuf.st_mode)) || */ | 71 | if ( /* (!(flags & ACTION_FOLLOWLINKS) && S_ISLNK(statbuf.st_mode)) || */ |
72 | !S_ISDIR(statbuf.st_mode) | 72 | !S_ISDIR(statbuf.st_mode) |
73 | ) { | 73 | ) { |
74 | return fileAction(fileName, &statbuf, userData, depth); | 74 | return fileAction(fileName, &statbuf, userData, depth); |
@@ -76,11 +76,11 @@ int recursive_action(const char *fileName, | |||
76 | 76 | ||
77 | /* It's a directory (or a link to one, and followLinks is set) */ | 77 | /* It's a directory (or a link to one, and followLinks is set) */ |
78 | 78 | ||
79 | if (!(flags & action_recurse)) { | 79 | if (!(flags & ACTION_RECURSE)) { |
80 | return dirAction(fileName, &statbuf, userData, depth); | 80 | return dirAction(fileName, &statbuf, userData, depth); |
81 | } | 81 | } |
82 | 82 | ||
83 | if (!(flags & action_depthFirst)) { | 83 | if (!(flags & ACTION_DEPTHFIRST)) { |
84 | status = dirAction(fileName, &statbuf, userData, depth); | 84 | status = dirAction(fileName, &statbuf, userData, depth); |
85 | if (!status) { | 85 | if (!status) { |
86 | goto done_nak_warn; | 86 | goto done_nak_warn; |
@@ -104,14 +104,14 @@ int recursive_action(const char *fileName, | |||
104 | if (nextFile == NULL) | 104 | if (nextFile == NULL) |
105 | continue; | 105 | continue; |
106 | /* now descend into it, forcing recursion. */ | 106 | /* now descend into it, forcing recursion. */ |
107 | if (!recursive_action(nextFile, flags | action_recurse, | 107 | if (!recursive_action(nextFile, flags | ACTION_RECURSE, |
108 | fileAction, dirAction, userData, depth+1)) { | 108 | fileAction, dirAction, userData, depth+1)) { |
109 | status = FALSE; | 109 | status = FALSE; |
110 | } | 110 | } |
111 | free(nextFile); | 111 | free(nextFile); |
112 | } | 112 | } |
113 | closedir(dir); | 113 | closedir(dir); |
114 | if (flags & action_depthFirst && | 114 | if ((flags & ACTION_DEPTHFIRST) && |
115 | !dirAction(fileName, &statbuf, userData, depth)) { | 115 | !dirAction(fileName, &statbuf, userData, depth)) { |
116 | goto done_nak_warn; | 116 | goto done_nak_warn; |
117 | } | 117 | } |
diff --git a/modutils/insmod.c b/modutils/insmod.c index 075969dcb..d4575e03b 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
@@ -4044,7 +4044,7 @@ int insmod_main( int argc, char **argv) | |||
4044 | module_dir = tmdn; | 4044 | module_dir = tmdn; |
4045 | else | 4045 | else |
4046 | module_dir = real_module_dir; | 4046 | module_dir = real_module_dir; |
4047 | recursive_action(module_dir, action_recurse, | 4047 | recursive_action(module_dir, ACTION_RECURSE, |
4048 | check_module_name_match, 0, m_fullName, 0); | 4048 | check_module_name_match, 0, m_fullName, 0); |
4049 | free(tmdn); | 4049 | free(tmdn); |
4050 | } | 4050 | } |
@@ -4059,7 +4059,7 @@ int insmod_main( int argc, char **argv) | |||
4059 | strcpy(module_dir, _PATH_MODULES); | 4059 | strcpy(module_dir, _PATH_MODULES); |
4060 | /* No module found under /lib/modules/`uname -r`, this | 4060 | /* No module found under /lib/modules/`uname -r`, this |
4061 | * time cast the net a bit wider. Search /lib/modules/ */ | 4061 | * time cast the net a bit wider. Search /lib/modules/ */ |
4062 | if (!recursive_action(module_dir, action_recurse, | 4062 | if (!recursive_action(module_dir, ACTION_RECURSE, |
4063 | check_module_name_match, 0, m_fullName, 0) | 4063 | check_module_name_match, 0, m_fullName, 0) |
4064 | ) { | 4064 | ) { |
4065 | if (m_filename == 0 | 4065 | if (m_filename == 0 |