1 /* vi: set sw=4 ts=4: */
3 * Mini find implementation for busybox
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Reworked by David Douthitt <n9ubh@callsign.net> and
8 * Matt Kraai <kraai@alumni.carnegiemellon.edu>.
10 * Licensed under the GPL version 2, see the file LICENSE in this tarball.
15 * # find file.txt -exec 'echo {}' '{} {}' ';'
16 * find: echo file.txt: No such file or directory
17 * # find file.txt -exec 'echo' '{} {}' '; '
18 * find: missing argument to `-exec'
19 * # find file.txt -exec 'echo {}' '{} {}' ';' junk
20 * find: paths must precede expression
21 * # find file.txt -exec 'echo {}' '{} {}' ';' junk ';'
22 * find: paths must precede expression
23 * # find file.txt -exec 'echo' '{} {}' ';'
25 * (strace: execve("/bin/echo", ["echo", "file.txt file.txt"], [ 30 vars ]))
26 * # find file.txt -exec 'echo' '{} {}' ';' -print -exec pwd ';'
30 * # find -name '*.c' -o -name '*.h'
31 * [shows files, *.c and *.h intermixed]
32 * # find file.txt -name '*f*' -o -name '*t*'
34 * # find file.txt -name '*z*' -o -name '*t*'
36 * # find file.txt -name '*f*' -o -name '*z*'
39 * # find t z -name '*t*' -print -o -name '*z*'
41 * # find t z t z -name '*t*' -o -name '*z*' -print
44 * # find t z t z '(' -name '*t*' -o -name '*z*' ')' -o -print
49 * ./busybox find "$@" | tee /tmp/bb_find
50 * echo ==================
51 * /path/to/gnu/find "$@" | tee /tmp/std_find
52 * echo ==================
53 * diff -u /tmp/std_find /tmp/bb_find && echo Identical
58 #if ENABLE_FEATURE_FIND_REGEX
62 /* This is a NOEXEC applet. Be very careful! */
65 USE_FEATURE_FIND_XDEV(static dev_t *xdev_dev;)
66 USE_FEATURE_FIND_XDEV(static int xdev_count;)
68 typedef int (*action_fp)(const char *fileName, struct stat *statbuf, void *);
72 #if ENABLE_FEATURE_FIND_NOT
76 #define ACTS(name, arg...) typedef struct { action a; arg; } action_##name;
77 #define ACTF(name) static int func_##name(const char *fileName, struct stat *statbuf, action_##name* ap)
79 ACTS(name, const char *pattern;)
80 USE_FEATURE_FIND_PATH( ACTS(path, const char *pattern;))
81 USE_FEATURE_FIND_REGEX( ACTS(regex, regex_t compiled_pattern;))
82 USE_FEATURE_FIND_PRINT0(ACTS(print0))
83 USE_FEATURE_FIND_TYPE( ACTS(type, int type_mask;))
84 USE_FEATURE_FIND_PERM( ACTS(perm, char perm_char; mode_t perm_mask;))
85 USE_FEATURE_FIND_MTIME( ACTS(mtime, char mtime_char; unsigned mtime_days;))
86 USE_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; unsigned mmin_mins;))
87 USE_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;))
88 USE_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;))
89 USE_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;))
90 USE_FEATURE_FIND_USER( ACTS(user, uid_t uid;))
91 USE_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
92 USE_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
93 USE_FEATURE_FIND_SIZE( ACTS(size, char size_char; off_t size;))
94 USE_FEATURE_FIND_PRUNE( ACTS(prune))
95 USE_FEATURE_FIND_DELETE(ACTS(delete))
97 static action ***actions;
98 static bool need_print = 1;
99 static int recurse_flags = ACTION_RECURSE;
101 #if ENABLE_FEATURE_FIND_EXEC
102 static unsigned count_subst(const char *str)
105 while ((str = strstr(str, "{}"))) {
113 static char* subst(const char *src, unsigned count, const char* filename)
115 char *buf, *dst, *end;
116 size_t flen = strlen(filename);
117 /* we replace each '{}' with filename: growth by strlen-2 */
118 buf = dst = xmalloc(strlen(src) + count*(flen-2) + 1);
119 while ((end = strstr(src, "{}"))) {
120 memcpy(dst, src, end - src);
123 memcpy(dst, filename, flen);
131 /* Return values of ACTFs ('action functions') are a bit mask:
132 * bit 1=1: prune (use SKIP constant for setting it)
133 * bit 0=1: matched successfully (TRUE)
136 static int exec_actions(action ***appp, const char *fileName, struct stat *statbuf)
143 /* "action group" is a set of actions ANDed together.
144 * groups are ORed together.
145 * We simply evaluate each group until we find one in which all actions
148 /* -prune is special: if it is encountered, then we won't
149 * descend into current directory. It doesn't matter whether
150 * action group (in which -prune sits) will succeed or not:
151 * find * -prune -name 'f*' -o -name 'm*' -- prunes every dir
152 * find * -name 'f*' -o -prune -name 'm*' -- prunes all dirs
153 * not starting with 'f' */
155 /* We invert TRUE bit (bit 0). Now 1 there means 'failure'.
156 * and bitwise OR in "rc |= TRUE ^ ap->f()" will:
157 * (1) make SKIP (-prune) bit stick; and (2) detect 'failure'.
158 * On return, bit is restored. */
161 while ((app = appp[++cur_group])) {
162 rc &= ~TRUE; /* 'success' so far, clear TRUE bit */
165 ap = app[++cur_action];
166 if (!ap) /* all actions in group were successful */
167 return rc ^ TRUE; /* restore TRUE bit */
168 rc |= TRUE ^ ap->f(fileName, statbuf, ap);
169 #if ENABLE_FEATURE_FIND_NOT
170 if (ap->invert) rc ^= TRUE;
172 if (rc & TRUE) /* current group failed, try next */
176 return rc ^ TRUE; /* restore TRUE bit */
182 const char *tmp = strrchr(fileName, '/');
187 if (!*tmp) { /* "foo/bar/". Oh no... go back to 'b' */
189 while (tmp != fileName && *--tmp != '/')
195 return fnmatch(ap->pattern, tmp, FNM_PERIOD) == 0;
197 #if ENABLE_FEATURE_FIND_PATH
200 return fnmatch(ap->pattern, fileName, 0) == 0;
203 #if ENABLE_FEATURE_FIND_REGEX
207 if (regexec(&ap->compiled_pattern, fileName, 1, &match, 0 /*eflags*/))
208 return 0; /* no match */
210 return 0; /* match doesn't start at pos 0 */
211 if (fileName[match.rm_eo])
212 return 0; /* match doesn't end exactly at end of pathname */
216 #if ENABLE_FEATURE_FIND_TYPE
219 return ((statbuf->st_mode & S_IFMT) == ap->type_mask);
222 #if ENABLE_FEATURE_FIND_PERM
225 /* -perm +mode: at least one of perm_mask bits are set */
226 if (ap->perm_char == '+')
227 return (statbuf->st_mode & ap->perm_mask) != 0;
228 /* -perm -mode: all of perm_mask are set */
229 if (ap->perm_char == '-')
230 return (statbuf->st_mode & ap->perm_mask) == ap->perm_mask;
231 /* -perm mode: file mode must match perm_mask */
232 return (statbuf->st_mode & 07777) == ap->perm_mask;
235 #if ENABLE_FEATURE_FIND_MTIME
238 time_t file_age = time(NULL) - statbuf->st_mtime;
239 time_t mtime_secs = ap->mtime_days * 24*60*60;
240 if (ap->mtime_char == '+')
241 return file_age >= mtime_secs + 24*60*60;
242 if (ap->mtime_char == '-')
243 return file_age < mtime_secs;
244 /* just numeric mtime */
245 return file_age >= mtime_secs && file_age < (mtime_secs + 24*60*60);
248 #if ENABLE_FEATURE_FIND_MMIN
251 time_t file_age = time(NULL) - statbuf->st_mtime;
252 time_t mmin_secs = ap->mmin_mins * 60;
253 if (ap->mmin_char == '+')
254 return file_age >= mmin_secs + 60;
255 if (ap->mmin_char == '-')
256 return file_age < mmin_secs;
257 /* just numeric mmin */
258 return file_age >= mmin_secs && file_age < (mmin_secs + 60);
261 #if ENABLE_FEATURE_FIND_NEWER
264 return (ap->newer_mtime < statbuf->st_mtime);
267 #if ENABLE_FEATURE_FIND_INUM
270 return (statbuf->st_ino == ap->inode_num);
273 #if ENABLE_FEATURE_FIND_EXEC
277 char *argv[ap->exec_argc + 1];
278 for (i = 0; i < ap->exec_argc; i++)
279 argv[i] = subst(ap->exec_argv[i], ap->subst_count[i], fileName);
280 argv[i] = NULL; /* terminate the list */
282 rc = spawn_and_wait(argv);
284 bb_perror_msg("%s", argv[0]);
289 return rc == 0; /* return 1 if exitcode 0 */
292 #if ENABLE_FEATURE_FIND_USER
295 return (statbuf->st_uid == ap->uid);
298 #if ENABLE_FEATURE_FIND_GROUP
301 return (statbuf->st_gid == ap->gid);
304 #if ENABLE_FEATURE_FIND_PRINT0
307 printf("%s%c", fileName, '\0');
316 #if ENABLE_FEATURE_FIND_PAREN
319 return exec_actions(ap->subexpr, fileName, statbuf);
322 #if ENABLE_FEATURE_FIND_SIZE
325 if (ap->size_char == '+')
326 return statbuf->st_size > ap->size;
327 if (ap->size_char == '-')
328 return statbuf->st_size < ap->size;
329 return statbuf->st_size == ap->size;
332 #if ENABLE_FEATURE_FIND_PRUNE
334 * -prune: if -depth is not given, return true and do not descend
335 * current dir; if -depth is given, return false with no effect.
337 * find dir -name 'asm-*' -prune -o -name '*.[chS]' -print
344 #if ENABLE_FEATURE_FIND_DELETE
348 if (S_ISDIR(statbuf->st_mode)) {
349 rc = rmdir(fileName);
351 rc = unlink(fileName);
354 bb_perror_msg("%s", fileName);
360 static int fileAction(const char *fileName, struct stat *statbuf, void *userData, int depth)
363 #if ENABLE_FEATURE_FIND_MAXDEPTH
364 int maxdepth = (int)(ptrdiff_t)userData;
366 if (depth > maxdepth) return SKIP;
369 #if ENABLE_FEATURE_FIND_XDEV
370 if (S_ISDIR(statbuf->st_mode) && xdev_count) {
371 for (i = 0; i < xdev_count; i++) {
372 if (xdev_dev[i] != statbuf->st_dev)
377 i = exec_actions(actions, fileName, statbuf);
378 /* Had no explicit -print[0] or -exec? then print */
379 if ((i & TRUE) && need_print)
381 /* Cannot return 0: our caller, recursive_action(),
382 * will perror() and skip dirs (if called on dir) */
383 return (i & SKIP) ? SKIP : TRUE;
387 #if ENABLE_FEATURE_FIND_TYPE
388 static int find_type(const char *type)
394 else if (*type == 'c')
396 else if (*type == 'd')
398 else if (*type == 'p')
400 else if (*type == 'f')
402 else if (*type == 'l')
404 else if (*type == 's')
407 if (mask == 0 || *(type + 1) != '\0')
408 bb_error_msg_and_die(bb_msg_invalid_arg, type, "-type");
414 #if ENABLE_FEATURE_FIND_PERM || ENABLE_FEATURE_FIND_MTIME \
415 || ENABLE_FEATURE_FIND_MMIN
416 static const char* plus_minus_num(const char* str)
418 if (*str == '-' || *str == '+')
424 static action*** parse_params(char **argv)
429 USE_FEATURE_FIND_NOT( PARM_char_not ,)
431 USE_FEATURE_FIND_PRINT0(PARM_print0 ,)
433 USE_FEATURE_FIND_PATH( PARM_path ,)
434 USE_FEATURE_FIND_REGEX( PARM_regex ,)
435 USE_FEATURE_FIND_TYPE( PARM_type ,)
436 USE_FEATURE_FIND_PERM( PARM_perm ,)
437 USE_FEATURE_FIND_MTIME( PARM_mtime ,)
438 USE_FEATURE_FIND_MMIN( PARM_mmin ,)
439 USE_FEATURE_FIND_NEWER( PARM_newer ,)
440 USE_FEATURE_FIND_INUM( PARM_inum ,)
441 USE_FEATURE_FIND_EXEC( PARM_exec ,)
442 USE_FEATURE_FIND_USER( PARM_user ,)
443 USE_FEATURE_FIND_GROUP( PARM_group ,)
444 USE_FEATURE_FIND_DEPTH( PARM_depth ,)
445 USE_FEATURE_FIND_PAREN( PARM_char_brace,)
446 USE_FEATURE_FIND_SIZE( PARM_size ,)
447 USE_FEATURE_FIND_PRUNE( PARM_prune ,)
448 USE_FEATURE_FIND_DELETE(PARM_delete ,)
452 USE_FEATURE_FIND_NOT( PARM_not ,)
456 static const char *const params[] = {
459 USE_FEATURE_FIND_NOT( "!" ,)
461 USE_FEATURE_FIND_PRINT0("-print0",)
463 USE_FEATURE_FIND_PATH( "-path" ,)
464 USE_FEATURE_FIND_REGEX( "-regex" ,)
465 USE_FEATURE_FIND_TYPE( "-type" ,)
466 USE_FEATURE_FIND_PERM( "-perm" ,)
467 USE_FEATURE_FIND_MTIME( "-mtime" ,)
468 USE_FEATURE_FIND_MMIN( "-mmin" ,)
469 USE_FEATURE_FIND_NEWER( "-newer" ,)
470 USE_FEATURE_FIND_INUM( "-inum" ,)
471 USE_FEATURE_FIND_EXEC( "-exec" ,)
472 USE_FEATURE_FIND_USER( "-user" ,)
473 USE_FEATURE_FIND_GROUP( "-group" ,)
474 USE_FEATURE_FIND_DEPTH( "-depth" ,)
475 USE_FEATURE_FIND_PAREN( "(" ,)
476 USE_FEATURE_FIND_SIZE( "-size" ,)
477 USE_FEATURE_FIND_PRUNE( "-prune" ,)
478 USE_FEATURE_FIND_DELETE("-delete",)
482 USE_FEATURE_FIND_NOT( "-not" ,)
488 unsigned cur_group = 0;
489 unsigned cur_action = 0;
490 USE_FEATURE_FIND_NOT( bool invert_flag = 0; )
492 /* 'static' doesn't work here! (gcc 4.1.2) */
493 action* alloc_action(int sizeof_struct, action_fp f)
496 appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(*appp));
497 appp[cur_group][cur_action++] = ap = xmalloc(sizeof_struct);
498 appp[cur_group][cur_action] = NULL;
500 USE_FEATURE_FIND_NOT( ap->invert = invert_flag; )
501 USE_FEATURE_FIND_NOT( invert_flag = 0; )
505 #define ALLOC_ACTION(name) (action_##name*)alloc_action(sizeof(action_##name), (action_fp) func_##name)
507 appp = xzalloc(2 * sizeof(appp[0])); /* appp[0],[1] == NULL */
509 /* Actions have side effects and return a true or false value
510 * We implement: -print, -print0, -exec
512 * The rest are tests.
514 * Tests and actions are grouped by operators
515 * ( expr ) Force precedence
516 * ! expr True if expr is false
517 * -not expr Same as ! expr
518 * expr1 [-a[nd]] expr2 And; expr2 is not evaluated if expr1 is false
519 * expr1 -o[r] expr2 Or; expr2 is not evaluated if expr1 is true
520 * expr1 , expr2 List; both expr1 and expr2 are always evaluated
521 * We implement: (), -a, -o
524 const char *arg = argv[0];
525 const char *arg1 = argv[1];
526 int parm = index_in_str_array(params, arg);
527 /* --- Operators --- */
528 if (parm == PARM_a USE_DESKTOP(|| parm == PARM_and)) {
529 /* no further special handling required */
531 else if (parm == PARM_o USE_DESKTOP(|| parm == PARM_or)) {
532 /* start new OR group */
534 appp = xrealloc(appp, (cur_group+2) * sizeof(*appp));
535 /*appp[cur_group] = NULL; - already NULL */
536 appp[cur_group+1] = NULL;
539 #if ENABLE_FEATURE_FIND_NOT
540 else if (parm == PARM_char_not USE_DESKTOP(|| parm == PARM_not)) {
541 /* also handles "find ! ! -name 'foo*'" */
546 /* --- Tests and actions --- */
547 else if (parm == PARM_print) {
549 /* GNU find ignores '!' here: "find ! -print" */
550 USE_FEATURE_FIND_NOT( invert_flag = 0; )
551 (void) ALLOC_ACTION(print);
553 #if ENABLE_FEATURE_FIND_PRINT0
554 else if (parm == PARM_print0) {
556 USE_FEATURE_FIND_NOT( invert_flag = 0; )
557 (void) ALLOC_ACTION(print0);
560 else if (parm == PARM_name) {
563 bb_error_msg_and_die(bb_msg_requires_arg, arg);
564 ap = ALLOC_ACTION(name);
567 #if ENABLE_FEATURE_FIND_PATH
568 else if (parm == PARM_path) {
571 bb_error_msg_and_die(bb_msg_requires_arg, arg);
572 ap = ALLOC_ACTION(path);
576 #if ENABLE_FEATURE_FIND_REGEX
577 else if (parm == PARM_regex) {
580 bb_error_msg_and_die(bb_msg_requires_arg, arg);
581 ap = ALLOC_ACTION(regex);
582 xregcomp(&ap->compiled_pattern, arg1, 0 /*cflags*/);
585 #if ENABLE_FEATURE_FIND_TYPE
586 else if (parm == PARM_type) {
589 bb_error_msg_and_die(bb_msg_requires_arg, arg);
590 ap = ALLOC_ACTION(type);
591 ap->type_mask = find_type(arg1);
594 #if ENABLE_FEATURE_FIND_PERM
595 /* -perm mode File's permission bits are exactly mode (octal or symbolic).
596 * Symbolic modes use mode 0 as a point of departure.
597 * -perm -mode All of the permission bits mode are set for the file.
598 * -perm +mode Any of the permission bits mode are set for the file.
600 else if (parm == PARM_perm) {
603 bb_error_msg_and_die(bb_msg_requires_arg, arg);
604 ap = ALLOC_ACTION(perm);
605 ap->perm_char = arg1[0];
606 arg1 = plus_minus_num(arg1);
608 if (!bb_parse_mode(arg1, &ap->perm_mask))
609 bb_error_msg_and_die("invalid mode: %s", arg1);
612 #if ENABLE_FEATURE_FIND_MTIME
613 else if (parm == PARM_mtime) {
616 bb_error_msg_and_die(bb_msg_requires_arg, arg);
617 ap = ALLOC_ACTION(mtime);
618 ap->mtime_char = arg1[0];
619 ap->mtime_days = xatoul(plus_minus_num(arg1));
622 #if ENABLE_FEATURE_FIND_MMIN
623 else if (parm == PARM_mmin) {
626 bb_error_msg_and_die(bb_msg_requires_arg, arg);
627 ap = ALLOC_ACTION(mmin);
628 ap->mmin_char = arg1[0];
629 ap->mmin_mins = xatoul(plus_minus_num(arg1));
632 #if ENABLE_FEATURE_FIND_NEWER
633 else if (parm == PARM_newer) {
635 struct stat stat_newer;
637 bb_error_msg_and_die(bb_msg_requires_arg, arg);
638 xstat(arg1, &stat_newer);
639 ap = ALLOC_ACTION(newer);
640 ap->newer_mtime = stat_newer.st_mtime;
643 #if ENABLE_FEATURE_FIND_INUM
644 else if (parm == PARM_inum) {
647 bb_error_msg_and_die(bb_msg_requires_arg, arg);
648 ap = ALLOC_ACTION(inum);
649 ap->inode_num = xatoul(arg1);
652 #if ENABLE_FEATURE_FIND_EXEC
653 else if (parm == PARM_exec) {
657 USE_FEATURE_FIND_NOT( invert_flag = 0; )
658 ap = ALLOC_ACTION(exec);
659 ap->exec_argv = ++argv; /* first arg after -exec */
662 if (!*argv) /* did not see ';' until end */
663 bb_error_msg_and_die(bb_msg_requires_arg, arg);
664 if (LONE_CHAR(argv[0], ';'))
669 if (ap->exec_argc == 0)
670 bb_error_msg_and_die(bb_msg_requires_arg, arg);
671 ap->subst_count = xmalloc(ap->exec_argc * sizeof(int));
674 ap->subst_count[i] = count_subst(ap->exec_argv[i]);
677 #if ENABLE_FEATURE_FIND_USER
678 else if (parm == PARM_user) {
681 bb_error_msg_and_die(bb_msg_requires_arg, arg);
682 ap = ALLOC_ACTION(user);
683 ap->uid = bb_strtou(arg1, NULL, 10);
685 ap->uid = xuname2uid(arg1);
688 #if ENABLE_FEATURE_FIND_GROUP
689 else if (parm == PARM_group) {
692 bb_error_msg_and_die(bb_msg_requires_arg, arg);
693 ap = ALLOC_ACTION(group);
694 ap->gid = bb_strtou(arg1, NULL, 10);
696 ap->gid = xgroup2gid(arg1);
699 #if ENABLE_FEATURE_FIND_DEPTH
700 else if (parm == PARM_depth) {
701 recurse_flags |= ACTION_DEPTHFIRST;
704 #if ENABLE_FEATURE_FIND_PAREN
705 else if (parm == PARM_char_brace) {
713 bb_error_msg_and_die("unpaired '('");
714 if (LONE_CHAR(*endarg, '('))
716 else if (LONE_CHAR(*endarg, ')') && !--nested) {
721 ap = ALLOC_ACTION(paren);
722 ap->subexpr = parse_params(argv + 1);
723 *endarg = (char*) ")"; /* restore NULLed parameter */
727 #if ENABLE_FEATURE_FIND_SIZE
728 else if (parm == PARM_size) {
729 /* -size n[bckw]: file uses n units of space
730 * b (default): units are 512-byte blocks
736 #define XATOU_SFX xatoull_sfx
738 #define XATOU_SFX xatoul_sfx
740 static const struct suffix_mult find_suffixes[] = {
750 bb_error_msg_and_die(bb_msg_requires_arg, arg);
751 ap = ALLOC_ACTION(size);
752 ap->size_char = arg1[0];
753 ap->size = XATOU_SFX(plus_minus_num(arg1), find_suffixes);
756 #if ENABLE_FEATURE_FIND_PRUNE
757 else if (parm == PARM_prune) {
758 USE_FEATURE_FIND_NOT( invert_flag = 0; )
759 (void) ALLOC_ACTION(prune);
762 #if ENABLE_FEATURE_FIND_DELETE
763 else if (parm == PARM_delete) {
765 recurse_flags |= ACTION_DEPTHFIRST;
766 (void) ALLOC_ACTION(delete);
770 bb_error_msg("unrecognized: %s", arg);
780 int find_main(int argc, char **argv);
781 int find_main(int argc, char **argv)
783 static const char *const options[] = {
785 USE_FEATURE_FIND_XDEV( "-xdev" ,)
786 USE_FEATURE_FIND_MAXDEPTH("-maxdepth",)
791 USE_FEATURE_FIND_XDEV( OPT_XDEV ,)
792 USE_FEATURE_FIND_MAXDEPTH(OPT_MAXDEPTH,)
797 int i, firstopt, status = EXIT_SUCCESS;
798 #if ENABLE_FEATURE_FIND_MAXDEPTH
799 int maxdepth = INT_MAX;
802 for (firstopt = 1; firstopt < argc; firstopt++) {
803 if (argv[firstopt][0] == '-')
805 if (ENABLE_FEATURE_FIND_NOT && LONE_CHAR(argv[firstopt], '!'))
807 #if ENABLE_FEATURE_FIND_PAREN
808 if (LONE_CHAR(argv[firstopt], '('))
813 argv[0] = (char*)".";
818 /* All options always return true. They always take effect
819 * rather than being processed only when their place in the
820 * expression is reached.
821 * We implement: -follow, -xdev, -maxdepth
823 /* Process options, and replace then with -a */
824 /* (-a will be ignored by recursive parser later) */
825 argp = &argv[firstopt];
826 while ((arg = argp[0])) {
827 int opt = index_in_str_array(options, arg);
828 if (opt == OPT_FOLLOW) {
829 recurse_flags |= ACTION_FOLLOWLINKS;
830 argp[0] = (char*)"-a";
832 #if ENABLE_FEATURE_FIND_XDEV
833 if (opt == OPT_XDEV) {
836 xdev_count = firstopt - 1;
837 xdev_dev = xmalloc(xdev_count * sizeof(dev_t));
838 for (i = 1; i < firstopt; i++) {
839 /* not xstat(): shouldn't bomb out on
840 * "find not_exist exist -xdev" */
841 if (stat(argv[i], &stbuf))
843 xdev_dev[i-1] = stbuf.st_dev;
846 argp[0] = (char*)"-a";
849 #if ENABLE_FEATURE_FIND_MAXDEPTH
850 if (opt == OPT_MAXDEPTH) {
853 maxdepth = xatoi_u(argp[1]);
854 argp[0] = (char*)"-a";
855 argp[1] = (char*)"-a";
862 actions = parse_params(&argv[firstopt]);
864 for (i = 1; i < firstopt; i++) {
865 if (!recursive_action(argv[i],
866 recurse_flags, /* flags */
867 fileAction, /* file action */
868 fileAction, /* dir action */
869 #if ENABLE_FEATURE_FIND_MAXDEPTH
870 (void*)maxdepth,/* user data */
872 NULL, /* user data */
875 status = EXIT_FAILURE;