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 GPLv2, see file LICENSE in this source tree.
14 * # find file.txt -exec 'echo {}' '{} {}' ';'
15 * find: echo file.txt: No such file or directory
16 * # find file.txt -exec 'echo' '{} {}' '; '
17 * find: missing argument to '-exec'
18 * # find file.txt -exec 'echo {}' '{} {}' ';' junk
19 * find: paths must precede expression
20 * # find file.txt -exec 'echo {}' '{} {}' ';' junk ';'
21 * find: paths must precede expression
22 * # find file.txt -exec 'echo' '{} {}' ';'
24 * (strace: execve("/bin/echo", ["echo", "file.txt file.txt"], [ 30 vars ]))
25 * # find file.txt -exec 'echo' '{} {}' ';' -print -exec pwd ';'
29 * # find -name '*.c' -o -name '*.h'
30 * [shows files, *.c and *.h intermixed]
31 * # find file.txt -name '*f*' -o -name '*t*'
33 * # find file.txt -name '*z*' -o -name '*t*'
35 * # find file.txt -name '*f*' -o -name '*z*'
38 * # find t z -name '*t*' -print -o -name '*z*'
40 * # find t z t z -name '*t*' -o -name '*z*' -print
43 * # find t z t z '(' -name '*t*' -o -name '*z*' ')' -o -print
47 * ./busybox find "$@" | tee /tmp/bb_find
48 * echo ==================
49 * /path/to/gnu/find "$@" | tee /tmp/std_find
50 * echo ==================
51 * diff -u /tmp/std_find /tmp/bb_find && echo Identical
54 //config: bool "find (14 kb)"
57 //config: find is used to search your system to find specified files.
59 //config:config FEATURE_FIND_PRINT0
60 //config: bool "Enable -print0: NUL-terminated output"
62 //config: depends on FIND
64 //config: Causes output names to be separated by a NUL character
65 //config: rather than a newline. This allows names that contain
66 //config: newlines and other whitespace to be more easily
67 //config: interpreted by other programs.
69 //config:config FEATURE_FIND_MTIME
70 //config: bool "Enable -mtime: modified time matching"
72 //config: depends on FIND
74 //config: Allow searching based on the modification time of
75 //config: files, in days.
77 //config:config FEATURE_FIND_MMIN
78 //config: bool "Enable -mmin: modified time matching by minutes"
80 //config: depends on FIND
82 //config: Allow searching based on the modification time of
83 //config: files, in minutes.
85 //config:config FEATURE_FIND_PERM
86 //config: bool "Enable -perm: permissions matching"
88 //config: depends on FIND
90 //config:config FEATURE_FIND_TYPE
91 //config: bool "Enable -type: file type matching (file/dir/link/...)"
93 //config: depends on FIND
95 //config: Enable searching based on file type (file,
96 //config: directory, socket, device, etc.).
98 //config:config FEATURE_FIND_EXECUTABLE
99 //config: bool "Enable -executable: file is executable"
101 //config: depends on FIND
103 //config:config FEATURE_FIND_XDEV
104 //config: bool "Enable -xdev: 'stay in filesystem'"
106 //config: depends on FIND
108 //config:config FEATURE_FIND_MAXDEPTH
109 //config: bool "Enable -mindepth N and -maxdepth N"
111 //config: depends on FIND
113 //config:config FEATURE_FIND_NEWER
114 //config: bool "Enable -newer: compare file modification times"
116 //config: depends on FIND
118 //config: Support the 'find -newer' option for finding any files which have
119 //config: modification time that is more recent than the specified FILE.
121 //config:config FEATURE_FIND_INUM
122 //config: bool "Enable -inum: inode number matching"
124 //config: depends on FIND
126 //config:config FEATURE_FIND_EXEC
127 //config: bool "Enable -exec: execute commands"
129 //config: depends on FIND
131 //config: Support the 'find -exec' option for executing commands based upon
132 //config: the files matched.
134 //config:config FEATURE_FIND_EXEC_PLUS
135 //config: bool "Enable -exec ... {} +"
137 //config: depends on FEATURE_FIND_EXEC
139 //config: Support the 'find -exec ... {} +' option for executing commands
140 //config: for all matched files at once.
141 //config: Without this option, -exec + is a synonym for -exec ;
142 //config: (IOW: it works correctly, but without expected speedup)
144 //config:config FEATURE_FIND_USER
145 //config: bool "Enable -user: username/uid matching"
147 //config: depends on FIND
149 //config:config FEATURE_FIND_GROUP
150 //config: bool "Enable -group: group/gid matching"
152 //config: depends on FIND
154 //config:config FEATURE_FIND_NOT
155 //config: bool "Enable the 'not' (!) operator"
157 //config: depends on FIND
159 //config: Support the '!' operator to invert the test results.
160 //config: If 'Enable full-blown desktop' is enabled, then will also support
161 //config: the non-POSIX notation '-not'.
163 //config:config FEATURE_FIND_DEPTH
164 //config: bool "Enable -depth"
166 //config: depends on FIND
168 //config: Process each directory's contents before the directory itself.
170 //config:config FEATURE_FIND_PAREN
171 //config: bool "Enable parens in options"
173 //config: depends on FIND
175 //config: Enable usage of parens '(' to specify logical order of arguments.
177 //config:config FEATURE_FIND_SIZE
178 //config: bool "Enable -size: file size matching"
180 //config: depends on FIND
182 //config:config FEATURE_FIND_PRUNE
183 //config: bool "Enable -prune: exclude subdirectories"
185 //config: depends on FIND
187 //config: If the file is a directory, don't descend into it. Useful for
188 //config: exclusion .svn and CVS directories.
190 //config:config FEATURE_FIND_QUIT
191 //config: bool "Enable -quit: exit"
193 //config: depends on FIND
195 //config: If this action is reached, 'find' exits.
197 //config:config FEATURE_FIND_DELETE
198 //config: bool "Enable -delete: delete files/dirs"
200 //config: depends on FIND && FEATURE_FIND_DEPTH
202 //config: Support the 'find -delete' option for deleting files and directories.
203 //config: WARNING: This option can do much harm if used wrong. Busybox will not
204 //config: try to protect the user from doing stupid things. Use with care.
206 //config:config FEATURE_FIND_PATH
207 //config: bool "Enable -path: match pathname with shell pattern"
209 //config: depends on FIND
211 //config: The -path option matches whole pathname instead of just filename.
213 //config:config FEATURE_FIND_REGEX
214 //config: bool "Enable -regex: match pathname with regex"
216 //config: depends on FIND
218 //config: The -regex option matches whole pathname against regular expression.
220 //config:config FEATURE_FIND_CONTEXT
221 //config: bool "Enable -context: security context matching"
223 //config: depends on FIND && SELINUX
225 //config: Support the 'find -context' option for matching security context.
227 //config:config FEATURE_FIND_LINKS
228 //config: bool "Enable -links: link count matching"
230 //config: depends on FIND
232 //config: Support the 'find -links' option for matching number of links.
234 //applet:IF_FIND(APPLET_NOEXEC(find, find, BB_DIR_USR_BIN, BB_SUID_DROP, find))
236 //kbuild:lib-$(CONFIG_FIND) += find.o
238 //usage:#define find_trivial_usage
239 //usage: "[-HL] [PATH]... [OPTIONS] [ACTIONS]"
240 //usage:#define find_full_usage "\n\n"
241 //usage: "Search for files and perform actions on them.\n"
242 //usage: "First failed action stops processing of current file.\n"
243 //usage: "Defaults: PATH is current directory, action is '-print'\n"
244 //usage: "\n -L,-follow Follow symlinks"
245 //usage: "\n -H ...on command line only"
246 //usage: IF_FEATURE_FIND_XDEV(
247 //usage: "\n -xdev Don't descend directories on other filesystems"
249 //usage: IF_FEATURE_FIND_MAXDEPTH(
250 //usage: "\n -maxdepth N Descend at most N levels. -maxdepth 0 applies"
251 //usage: "\n actions to command line arguments only"
252 //usage: "\n -mindepth N Don't act on first N levels"
254 //usage: IF_FEATURE_FIND_DEPTH(
255 //usage: "\n -depth Act on directory *after* traversing it"
258 //usage: "\nActions:"
259 //usage: IF_FEATURE_FIND_PAREN(
260 //usage: "\n ( ACTIONS ) Group actions for -o / -a"
262 //usage: IF_FEATURE_FIND_NOT(
263 //usage: "\n ! ACT Invert ACT's success/failure"
265 //usage: "\n ACT1 [-a] ACT2 If ACT1 fails, stop, else do ACT2"
266 //usage: "\n ACT1 -o ACT2 If ACT1 succeeds, stop, else do ACT2"
267 //usage: "\n Note: -a has higher priority than -o"
268 //usage: "\n -name PATTERN Match file name (w/o directory name) to PATTERN"
269 //usage: "\n -iname PATTERN Case insensitive -name"
270 //usage: IF_FEATURE_FIND_PATH(
271 //usage: "\n -path PATTERN Match path to PATTERN"
272 //usage: "\n -ipath PATTERN Case insensitive -path"
274 //usage: IF_FEATURE_FIND_REGEX(
275 //usage: "\n -regex PATTERN Match path to regex PATTERN"
277 //usage: IF_FEATURE_FIND_TYPE(
278 //usage: "\n -type X File type is X (one of: f,d,l,b,c,s,p)"
280 //usage: IF_FEATURE_FIND_EXECUTABLE(
281 //usage: "\n -executable File is executable"
283 //usage: IF_FEATURE_FIND_PERM(
284 //usage: "\n -perm MASK At least one mask bit (+MASK), all bits (-MASK),"
285 //usage: "\n or exactly MASK bits are set in file's mode"
287 //usage: IF_FEATURE_FIND_MTIME(
288 //usage: "\n -mtime DAYS mtime is greater than (+N), less than (-N),"
289 //usage: "\n or exactly N days in the past"
291 //usage: IF_FEATURE_FIND_MMIN(
292 //usage: "\n -mmin MINS mtime is greater than (+N), less than (-N),"
293 //usage: "\n or exactly N minutes in the past"
295 //usage: IF_FEATURE_FIND_NEWER(
296 //usage: "\n -newer FILE mtime is more recent than FILE's"
298 //usage: IF_FEATURE_FIND_INUM(
299 //usage: "\n -inum N File has inode number N"
301 //usage: IF_FEATURE_FIND_USER(
302 //usage: "\n -user NAME/ID File is owned by given user"
304 //usage: IF_FEATURE_FIND_GROUP(
305 //usage: "\n -group NAME/ID File is owned by given group"
307 //usage: IF_FEATURE_FIND_SIZE(
308 //usage: "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))"
309 //usage: "\n +/-N: file size is bigger/smaller than N"
311 //usage: IF_FEATURE_FIND_LINKS(
312 //usage: "\n -links N Number of links is greater than (+N), less than (-N),"
313 //usage: "\n or exactly N"
315 //usage: IF_FEATURE_FIND_CONTEXT(
316 //usage: "\n -context CTX File has specified security context"
318 //usage: IF_FEATURE_FIND_PRUNE(
319 //usage: "\n -prune If current file is directory, don't descend into it"
321 //usage: "\nIf none of the following actions is specified, -print is assumed"
322 //usage: "\n -print Print file name"
323 //usage: IF_FEATURE_FIND_PRINT0(
324 //usage: "\n -print0 Print file name, NUL terminated"
326 //usage: IF_FEATURE_FIND_EXEC(
327 //usage: "\n -exec CMD ARG ; Run CMD with all instances of {} replaced by"
328 //usage: "\n file name. Fails if CMD exits with nonzero"
330 //usage: IF_FEATURE_FIND_EXEC_PLUS(
331 //usage: "\n -exec CMD ARG + Run CMD with {} replaced by list of file names"
333 //usage: IF_FEATURE_FIND_DELETE(
334 //usage: "\n -delete Delete current file/directory. Turns on -depth option"
336 //usage: IF_FEATURE_FIND_QUIT(
337 //usage: "\n -quit Exit"
340 //usage:#define find_example_usage
341 //usage: "$ find / -name passwd\n"
342 //usage: "/etc/passwd\n"
346 #include "common_bufsiz.h"
347 #if ENABLE_FEATURE_FIND_REGEX
352 # define FNM_CASEFOLD 0
356 # define dbg(...) ((void)0)
358 # define dbg(...) bb_error_msg(__VA_ARGS__)
362 /* This is a NOEXEC applet. Be very careful! */
365 typedef int (*action_fp)(const char *fileName, const struct stat *statbuf, void *) FAST_FUNC;
369 #if ENABLE_FEATURE_FIND_NOT
374 #define ACTS(name, ...) typedef struct { action a; __VA_ARGS__ } action_##name;
376 static int FAST_FUNC func_##name(const char *fileName UNUSED_PARAM, \
377 const struct stat *statbuf UNUSED_PARAM, \
378 action_##name* ap UNUSED_PARAM)
381 ACTS(name, const char *pattern; bool iname;)
382 IF_FEATURE_FIND_PATH( ACTS(path, const char *pattern; bool ipath;))
383 IF_FEATURE_FIND_REGEX( ACTS(regex, regex_t compiled_pattern;))
384 IF_FEATURE_FIND_PRINT0( ACTS(print0))
385 IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;))
386 IF_FEATURE_FIND_EXECUTABLE(ACTS(executable))
387 IF_FEATURE_FIND_PERM( ACTS(perm, char perm_char; mode_t perm_mask;))
388 IF_FEATURE_FIND_MTIME( ACTS(mtime, char mtime_char; unsigned mtime_days;))
389 IF_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; unsigned mmin_mins;))
390 IF_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;))
391 IF_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;))
392 IF_FEATURE_FIND_USER( ACTS(user, uid_t uid;))
393 IF_FEATURE_FIND_SIZE( ACTS(size, char size_char; off_t size;))
394 IF_FEATURE_FIND_CONTEXT(ACTS(context, security_context_t context;))
395 IF_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
396 IF_FEATURE_FIND_PRUNE( ACTS(prune))
397 IF_FEATURE_FIND_QUIT( ACTS(quit))
398 IF_FEATURE_FIND_DELETE( ACTS(delete))
399 IF_FEATURE_FIND_EXEC( ACTS(exec,
400 char **exec_argv; /* -exec ARGS */
401 unsigned *subst_count;
402 int exec_argc; /* count of ARGS */
403 IF_FEATURE_FIND_EXEC_PLUS(
405 * filelist is NULL if "exec ;"
406 * non-NULL if "exec +"
413 IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
414 IF_FEATURE_FIND_LINKS( ACTS(links, char links_char; int links_count;))
417 IF_FEATURE_FIND_XDEV(dev_t *xdev_dev;)
418 IF_FEATURE_FIND_XDEV(int xdev_count;)
419 #if ENABLE_FEATURE_FIND_MAXDEPTH
425 smalluint exitstatus;
426 recurse_flags_t recurse_flags;
427 IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;)
429 #define G (*(struct globals*)bb_common_bufsiz1)
430 #define INIT_G() do { \
431 setup_common_bufsiz(); \
432 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
433 /* we have to zero it out because of NOEXEC */ \
434 memset(&G, 0, sizeof(G)); \
435 IF_FEATURE_FIND_MAXDEPTH(G.minmaxdepth[1] = INT_MAX;) \
436 IF_FEATURE_FIND_EXEC_PLUS(G.max_argv_len = bb_arg_max() - 2048;) \
438 G.recurse_flags = ACTION_RECURSE; \
441 /* Return values of ACTFs ('action functions') are a bit mask:
442 * bit 1=1: prune (use SKIP constant for setting it)
443 * bit 0=1: matched successfully (TRUE)
446 static int exec_actions(action ***appp, const char *fileName, const struct stat *statbuf)
453 /* "action group" is a set of actions ANDed together.
454 * groups are ORed together.
455 * We simply evaluate each group until we find one in which all actions
458 /* -prune is special: if it is encountered, then we won't
459 * descend into current directory. It doesn't matter whether
460 * action group (in which -prune sits) will succeed or not:
461 * find * -prune -name 'f*' -o -name 'm*' -- prunes every dir
462 * find * -name 'f*' -o -prune -name 'm*' -- prunes all dirs
463 * not starting with 'f' */
465 /* We invert TRUE bit (bit 0). Now 1 there means 'failure'.
466 * and bitwise OR in "rc |= TRUE ^ ap->f()" will:
467 * (1) make SKIP (-prune) bit stick; and (2) detect 'failure'.
468 * On return, bit is restored. */
471 while ((app = appp[++cur_group]) != NULL) {
472 rc &= ~TRUE; /* 'success' so far, clear TRUE bit */
475 ap = app[++cur_action];
476 if (!ap) /* all actions in group were successful */
477 return rc ^ TRUE; /* restore TRUE bit */
478 rc |= TRUE ^ ap->f(fileName, statbuf, ap);
479 #if ENABLE_FEATURE_FIND_NOT
480 if (ap->invert) rc ^= TRUE;
482 dbg("grp %d action %d rc:0x%x", cur_group, cur_action, rc);
483 if (rc & TRUE) /* current group failed, try next */
487 dbg("returning:0x%x", rc ^ TRUE);
488 return rc ^ TRUE; /* restore TRUE bit */
492 static char *strcpy_upcase(char *dst, const char *src)
496 unsigned char ch = *src++;
497 if (ch >= 'a' && ch <= 'z')
510 const char *tmp = bb_basename(fileName);
511 /* GNU findutils: find DIR/ -name DIR
512 * prints "DIR/" (DIR// prints "DIR//" etc).
513 * Need to strip trailing "/".
514 * Such names can come only from top-level names, but
515 * we can't do this before recursive_action() call,
516 * since then "find FILE/ -name FILE"
517 * would also work (on non-directories), which is wrong.
519 char *trunc_slash = NULL;
522 /* "foo/bar/[//...]" */
523 while (tmp != fileName && tmp[-1] == '/')
525 if (tmp == fileName) { /* entire fileName is "//.."? */
526 /* yes, convert "//..." to "/"
528 * find / -maxdepth 1 -name /: prints /
529 * find // -maxdepth 1 -name /: prints //
530 * find / -maxdepth 1 -name //: prints nothing
531 * find // -maxdepth 1 -name //: prints nothing
534 trunc_slash = (char*)tmp + 1;
536 /* no, it's "foo/bar/[//...]", go back to 'b' */
537 trunc_slash = (char*)tmp;
538 while (tmp != fileName && tmp[-1] != '/')
543 /* Was using FNM_PERIOD flag too,
544 * but somewhere between 4.1.20 and 4.4.0 GNU find stopped using it.
545 * find -name '*foo' should match .foo too:
547 if (trunc_slash) *trunc_slash = '\0';
549 r = fnmatch(ap->pattern, tmp, (ap->iname ? FNM_CASEFOLD : 0));
552 tmp = strcpy_upcase(alloca(strlen(tmp) + 1), tmp);
553 r = fnmatch(ap->pattern, tmp, 0);
555 if (trunc_slash) *trunc_slash = '/';
559 #if ENABLE_FEATURE_FIND_PATH
563 return fnmatch(ap->pattern, fileName, (ap->ipath ? FNM_CASEFOLD : 0)) == 0;
566 fileName = strcpy_upcase(alloca(strlen(fileName) + 1), fileName);
567 return fnmatch(ap->pattern, fileName, 0) == 0;
571 #if ENABLE_FEATURE_FIND_REGEX
575 if (regexec(&ap->compiled_pattern, fileName, 1, &match, 0 /*eflags*/))
576 return 0; /* no match */
578 return 0; /* match doesn't start at pos 0 */
579 if (fileName[match.rm_eo])
580 return 0; /* match doesn't end exactly at end of pathname */
584 #if ENABLE_FEATURE_FIND_TYPE
587 return ((statbuf->st_mode & S_IFMT) == ap->type_mask);
590 #if ENABLE_FEATURE_FIND_EXECUTABLE
593 return access(fileName, X_OK) == 0;
596 #if ENABLE_FEATURE_FIND_PERM
599 /* -perm [+/]mode: at least one of perm_mask bits are set */
600 if (ap->perm_char == '+' || ap->perm_char == '/')
601 return (statbuf->st_mode & ap->perm_mask) != 0;
602 /* -perm -mode: all of perm_mask are set */
603 if (ap->perm_char == '-')
604 return (statbuf->st_mode & ap->perm_mask) == ap->perm_mask;
605 /* -perm mode: file mode must match perm_mask */
606 return (statbuf->st_mode & 07777) == ap->perm_mask;
609 #if ENABLE_FEATURE_FIND_MTIME
612 time_t file_age = time(NULL) - statbuf->st_mtime;
613 time_t mtime_secs = ap->mtime_days * 24*60*60;
614 if (ap->mtime_char == '+')
615 return file_age >= mtime_secs + 24*60*60;
616 if (ap->mtime_char == '-')
617 return file_age < mtime_secs;
618 /* just numeric mtime */
619 return file_age >= mtime_secs && file_age < (mtime_secs + 24*60*60);
622 #if ENABLE_FEATURE_FIND_MMIN
625 time_t file_age = time(NULL) - statbuf->st_mtime;
626 time_t mmin_secs = ap->mmin_mins * 60;
627 if (ap->mmin_char == '+')
628 return file_age >= mmin_secs + 60;
629 if (ap->mmin_char == '-')
630 return file_age < mmin_secs;
631 /* just numeric mmin */
632 return file_age >= mmin_secs && file_age < (mmin_secs + 60);
635 #if ENABLE_FEATURE_FIND_NEWER
638 return (ap->newer_mtime < statbuf->st_mtime);
641 #if ENABLE_FEATURE_FIND_INUM
644 return (statbuf->st_ino == ap->inode_num);
647 #if ENABLE_FEATURE_FIND_EXEC
648 static int do_exec(action_exec *ap, const char *fileName)
651 # if ENABLE_FEATURE_FIND_EXEC_PLUS
652 int size = ap->exec_argc + ap->filelist_idx + 1;
654 int size = ap->exec_argc + 1;
656 # if ENABLE_USE_PORTABLE_CODE
657 char **argv = alloca(sizeof(char*) * size);
658 # else /* gcc 4.3.1 generates smaller code: */
663 for (i = 0; i < ap->exec_argc; i++) {
664 const char *arg = ap->exec_argv[i];
666 # if ENABLE_FEATURE_FIND_EXEC_PLUS
668 /* Handling "-exec +"
669 * Only one exec_argv[i] has substitution in it.
670 * Expand that one exec_argv[i] into file list.
672 if (ap->subst_count[i] == 0) {
673 *pp++ = xstrdup(arg);
676 while (ap->filelist[j]) {
677 /* 2nd arg here should be ap->subst_count[i], but it is always 1: */
678 *pp++ = xmalloc_substitute_string(arg, 1, "{}", ap->filelist[j]);
679 free(ap->filelist[j]);
686 /* Handling "-exec ;" */
687 *pp++ = xmalloc_substitute_string(arg, ap->subst_count[i], "{}", fileName);
690 *pp = NULL; /* terminate the list */
692 # if ENABLE_FEATURE_FIND_EXEC_PLUS
694 ap->filelist[0] = NULL;
695 ap->filelist_idx = 0;
700 rc = spawn_and_wait(argv);
702 bb_simple_perror_msg(argv[0]);
707 return rc == 0; /* return 1 if exitcode 0 */
711 # if ENABLE_FEATURE_FIND_EXEC_PLUS
715 ap->filelist = xrealloc_vector(ap->filelist, 8, ap->filelist_idx);
716 ap->filelist[ap->filelist_idx++] = xstrdup(fileName);
717 ap->file_len += strlen(fileName) + sizeof(char*) + 1;
718 /* If we have lots of files already, exec the command */
720 if (ap->file_len >= G.max_argv_len)
721 rc = do_exec(ap, NULL);
725 return do_exec(ap, fileName);
727 # if ENABLE_FEATURE_FIND_EXEC_PLUS
728 static int flush_exec_plus(void)
732 action ***appp = G.actions;
733 while ((app = *appp++) != NULL) {
734 while ((ap = *app++) != NULL) {
735 if (ap->f == (action_fp)func_exec) {
736 action_exec *ae = (void*)ap;
737 if (ae->filelist_idx != 0) {
738 int rc = do_exec(ae, NULL);
739 # if ENABLE_FEATURE_FIND_NOT
740 if (ap->invert) rc = !rc;
752 #if ENABLE_FEATURE_FIND_USER
755 return (statbuf->st_uid == ap->uid);
758 #if ENABLE_FEATURE_FIND_GROUP
761 return (statbuf->st_gid == ap->gid);
764 #if ENABLE_FEATURE_FIND_PRINT0
767 printf("%s%c", fileName, '\0');
776 #if ENABLE_FEATURE_FIND_PAREN
779 return exec_actions(ap->subexpr, fileName, statbuf);
782 #if ENABLE_FEATURE_FIND_SIZE
785 if (ap->size_char == '+')
786 return statbuf->st_size > ap->size;
787 if (ap->size_char == '-')
788 return statbuf->st_size < ap->size;
789 return statbuf->st_size == ap->size;
792 #if ENABLE_FEATURE_FIND_PRUNE
794 * -prune: if -depth is not given, return true and do not descend
795 * current dir; if -depth is given, return false with no effect.
797 * find dir -name 'asm-*' -prune -o -name '*.[chS]' -print
804 #if ENABLE_FEATURE_FIND_QUIT
810 #if ENABLE_FEATURE_FIND_DELETE
814 if (S_ISDIR(statbuf->st_mode)) {
815 /* "find . -delete" skips rmdir(".") */
817 if (NOT_LONE_CHAR(fileName, '.'))
818 rc = rmdir(fileName);
820 rc = unlink(fileName);
823 bb_simple_perror_msg(fileName);
827 #if ENABLE_FEATURE_FIND_CONTEXT
830 security_context_t con;
833 if (G.recurse_flags & ACTION_FOLLOWLINKS) {
834 rc = getfilecon(fileName, &con);
836 rc = lgetfilecon(fileName, &con);
840 rc = strcmp(ap->context, con);
845 #if ENABLE_FEATURE_FIND_LINKS
848 switch(ap->links_char) {
849 case '-' : return (statbuf->st_nlink < ap->links_count);
850 case '+' : return (statbuf->st_nlink > ap->links_count);
851 default: return (statbuf->st_nlink == ap->links_count);
856 static int FAST_FUNC fileAction(const char *fileName,
857 struct stat *statbuf,
858 void *userData UNUSED_PARAM,
859 int depth IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM))
864 #if ENABLE_FEATURE_FIND_XDEV
865 if (S_ISDIR(statbuf->st_mode) && G.xdev_count) {
867 for (i = 0; i < G.xdev_count; i++) {
868 if (G.xdev_dev[i] == statbuf->st_dev)
871 //bb_error_msg("'%s': not same fs", fileName);
877 #if ENABLE_FEATURE_FIND_MAXDEPTH
878 if (depth < G.minmaxdepth[0]) {
880 return TRUE; /* skip this, continue recursing */
881 return SKIP; /* stop recursing */
883 if (depth > G.minmaxdepth[1])
884 return SKIP; /* stop recursing */
887 r = exec_actions(G.actions, fileName, statbuf);
888 /* Had no explicit -print[0] or -exec? then print */
889 if ((r & TRUE) && G.need_print)
892 #if ENABLE_FEATURE_FIND_MAXDEPTH
893 if (S_ISDIR(statbuf->st_mode)) {
894 if (depth == G.minmaxdepth[1])
898 /* -xdev stops on mountpoints, but AFTER mountpoit itself
899 * is processed as usual */
904 /* Cannot return 0: our caller, recursive_action(),
905 * will perror() and skip dirs (if called on dir) */
906 return (r & SKIP) ? SKIP : TRUE;
910 #if ENABLE_FEATURE_FIND_TYPE
911 static int find_type(const char *type)
917 else if (*type == 'c')
919 else if (*type == 'd')
921 else if (*type == 'p')
923 else if (*type == 'f')
925 else if (*type == 'l')
927 else if (*type == 's')
930 if (mask == 0 || type[1] != '\0')
931 bb_error_msg_and_die(bb_msg_invalid_arg_to, type, "-type");
937 #if ENABLE_FEATURE_FIND_PERM \
938 || ENABLE_FEATURE_FIND_MTIME || ENABLE_FEATURE_FIND_MMIN \
939 || ENABLE_FEATURE_FIND_SIZE || ENABLE_FEATURE_FIND_LINKS
940 static const char* plus_minus_num(const char* str)
942 if (*str == '-' || *str == '+')
948 /* Say no to GCCism */
949 #define USE_NESTED_FUNCTION 0
951 #if !USE_NESTED_FUNCTION
956 IF_FEATURE_FIND_NOT( bool invert_flag; )
958 static action* alloc_action(struct pp_locals *ppl, int sizeof_struct, action_fp f)
960 action *ap = xzalloc(sizeof_struct);
962 action ***group = &ppl->appp[ppl->cur_group];
963 *group = app = xrealloc(*group, (ppl->cur_action+2) * sizeof(ppl->appp[0][0]));
964 app[ppl->cur_action++] = ap;
965 app[ppl->cur_action] = NULL;
967 IF_FEATURE_FIND_NOT( ap->invert = ppl->invert_flag; )
968 IF_FEATURE_FIND_NOT( ppl->invert_flag = 0; )
973 static action*** parse_params(char **argv)
977 IF_FEATURE_FIND_XDEV( OPT_XDEV ,)
978 IF_FEATURE_FIND_DEPTH( OPT_DEPTH ,)
981 IF_FEATURE_FIND_NOT( PARM_char_not ,)
985 IF_FEATURE_FIND_NOT( PARM_not ,)
988 IF_FEATURE_FIND_PRINT0( PARM_print0 ,)
989 IF_FEATURE_FIND_PRUNE( PARM_prune ,)
990 IF_FEATURE_FIND_QUIT( PARM_quit ,)
991 IF_FEATURE_FIND_DELETE( PARM_delete ,)
992 IF_FEATURE_FIND_EXEC( PARM_exec ,)
993 IF_FEATURE_FIND_EXECUTABLE(PARM_executable,)
994 IF_FEATURE_FIND_PAREN( PARM_char_brace,)
995 /* All options/actions starting from here require argument */
998 IF_FEATURE_FIND_PATH( PARM_path ,)
1000 /* -wholename is a synonym for -path */
1001 /* We support it because Linux kernel's "make tags" uses it */
1002 IF_FEATURE_FIND_PATH( PARM_wholename ,)
1004 IF_FEATURE_FIND_PATH( PARM_ipath ,)
1005 IF_FEATURE_FIND_REGEX( PARM_regex ,)
1006 IF_FEATURE_FIND_TYPE( PARM_type ,)
1007 IF_FEATURE_FIND_PERM( PARM_perm ,)
1008 IF_FEATURE_FIND_MTIME( PARM_mtime ,)
1009 IF_FEATURE_FIND_MMIN( PARM_mmin ,)
1010 IF_FEATURE_FIND_NEWER( PARM_newer ,)
1011 IF_FEATURE_FIND_INUM( PARM_inum ,)
1012 IF_FEATURE_FIND_USER( PARM_user ,)
1013 IF_FEATURE_FIND_GROUP( PARM_group ,)
1014 IF_FEATURE_FIND_SIZE( PARM_size ,)
1015 IF_FEATURE_FIND_CONTEXT(PARM_context ,)
1016 IF_FEATURE_FIND_LINKS( PARM_links ,)
1017 IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,OPT_MAXDEPTH,)
1020 static const char params[] ALIGN1 =
1022 IF_FEATURE_FIND_XDEV( "-xdev\0" )
1023 IF_FEATURE_FIND_DEPTH( "-depth\0" )
1026 IF_FEATURE_FIND_NOT( "!\0" )
1030 IF_FEATURE_FIND_NOT( "-not\0" )
1033 IF_FEATURE_FIND_PRINT0( "-print0\0" )
1034 IF_FEATURE_FIND_PRUNE( "-prune\0" )
1035 IF_FEATURE_FIND_QUIT( "-quit\0" )
1036 IF_FEATURE_FIND_DELETE( "-delete\0" )
1037 IF_FEATURE_FIND_EXEC( "-exec\0" )
1038 IF_FEATURE_FIND_EXECUTABLE("-executable\0")
1039 IF_FEATURE_FIND_PAREN( "(\0" )
1040 /* All options/actions starting from here require argument */
1043 IF_FEATURE_FIND_PATH( "-path\0" )
1045 IF_FEATURE_FIND_PATH( "-wholename\0")
1047 IF_FEATURE_FIND_PATH( "-ipath\0" )
1048 IF_FEATURE_FIND_REGEX( "-regex\0" )
1049 IF_FEATURE_FIND_TYPE( "-type\0" )
1050 IF_FEATURE_FIND_PERM( "-perm\0" )
1051 IF_FEATURE_FIND_MTIME( "-mtime\0" )
1052 IF_FEATURE_FIND_MMIN( "-mmin\0" )
1053 IF_FEATURE_FIND_NEWER( "-newer\0" )
1054 IF_FEATURE_FIND_INUM( "-inum\0" )
1055 IF_FEATURE_FIND_USER( "-user\0" )
1056 IF_FEATURE_FIND_GROUP( "-group\0" )
1057 IF_FEATURE_FIND_SIZE( "-size\0" )
1058 IF_FEATURE_FIND_CONTEXT("-context\0")
1059 IF_FEATURE_FIND_LINKS( "-links\0" )
1060 IF_FEATURE_FIND_MAXDEPTH("-mindepth\0""-maxdepth\0")
1063 #if !USE_NESTED_FUNCTION
1064 struct pp_locals ppl;
1065 #define appp (ppl.appp )
1066 #define cur_group (ppl.cur_group )
1067 #define cur_action (ppl.cur_action )
1068 #define invert_flag (ppl.invert_flag)
1069 #define ALLOC_ACTION(name) (action_##name*)alloc_action(&ppl, sizeof(action_##name), (action_fp) func_##name)
1073 unsigned cur_action;
1074 IF_FEATURE_FIND_NOT( bool invert_flag; )
1076 /* This is the only place in busybox where we use nested function.
1077 * So far more standard alternatives were bigger. */
1078 /* Auto decl suppresses "func without a prototype" warning: */
1079 auto action* alloc_action(int sizeof_struct, action_fp f);
1080 action* alloc_action(int sizeof_struct, action_fp f)
1083 appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(appp[0][0]));
1084 appp[cur_group][cur_action++] = ap = xzalloc(sizeof_struct);
1085 appp[cur_group][cur_action] = NULL;
1087 IF_FEATURE_FIND_NOT( ap->invert = invert_flag; )
1088 IF_FEATURE_FIND_NOT( invert_flag = 0; )
1091 #define ALLOC_ACTION(name) (action_##name*)alloc_action(sizeof(action_##name), (action_fp) func_##name)
1096 IF_FEATURE_FIND_NOT( invert_flag = 0; )
1097 appp = xzalloc(2 * sizeof(appp[0])); /* appp[0],[1] == NULL */
1100 const char *arg = argv[0];
1101 int parm = index_in_strings(params, arg);
1102 const char *arg1 = argv[1];
1104 dbg("arg:'%s' arg1:'%s' parm:%d PARM_type:%d", arg, arg1, parm, PARM_type);
1106 if (parm >= PARM_name) {
1107 /* All options/actions starting from -name require argument */
1109 bb_error_msg_and_die(bb_msg_requires_arg, arg);
1113 /* We can use big switch() here, but on i386
1114 * it doesn't give smaller code. Other arches? */
1116 /* Options always return true. They always take effect
1117 * rather than being processed only when their place in the
1118 * expression is reached.
1121 if (parm == OPT_FOLLOW) {
1122 dbg("follow enabled: %d", __LINE__);
1123 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
1125 #if ENABLE_FEATURE_FIND_XDEV
1126 else if (parm == OPT_XDEV) {
1127 dbg("%d", __LINE__);
1131 #if ENABLE_FEATURE_FIND_MAXDEPTH
1132 else if (parm == OPT_MINDEPTH || parm == OPT_MINDEPTH + 1) {
1133 dbg("%d", __LINE__);
1134 G.minmaxdepth[parm - OPT_MINDEPTH] = xatoi_positive(arg1);
1137 #if ENABLE_FEATURE_FIND_DEPTH
1138 else if (parm == OPT_DEPTH) {
1139 dbg("%d", __LINE__);
1140 G.recurse_flags |= ACTION_DEPTHFIRST;
1143 /* Actions are grouped by operators
1144 * ( expr ) Force precedence
1145 * ! expr True if expr is false
1146 * -not expr Same as ! expr
1147 * expr1 [-a[nd]] expr2 And; expr2 is not evaluated if expr1 is false
1148 * expr1 -o[r] expr2 Or; expr2 is not evaluated if expr1 is true
1149 * expr1 , expr2 List; both expr1 and expr2 are always evaluated
1150 * We implement: (), -a, -o
1153 else if (parm == PARM_a IF_DESKTOP(|| parm == PARM_and)) {
1154 dbg("%d", __LINE__);
1155 /* no further special handling required */
1157 else if (parm == PARM_o IF_DESKTOP(|| parm == PARM_or)) {
1158 dbg("%d", __LINE__);
1159 /* start new OR group */
1161 appp = xrealloc(appp, (cur_group+2) * sizeof(appp[0]));
1162 /*appp[cur_group] = NULL; - already NULL */
1163 appp[cur_group+1] = NULL;
1166 #if ENABLE_FEATURE_FIND_NOT
1167 else if (parm == PARM_char_not IF_DESKTOP(|| parm == PARM_not)) {
1168 /* also handles "find ! ! -name 'foo*'" */
1170 dbg("invert_flag:%d", invert_flag);
1174 else if (parm == PARM_print) {
1175 dbg("%d", __LINE__);
1177 (void) ALLOC_ACTION(print);
1179 #if ENABLE_FEATURE_FIND_PRINT0
1180 else if (parm == PARM_print0) {
1181 dbg("%d", __LINE__);
1183 (void) ALLOC_ACTION(print0);
1186 #if ENABLE_FEATURE_FIND_PRUNE
1187 else if (parm == PARM_prune) {
1188 dbg("%d", __LINE__);
1189 (void) ALLOC_ACTION(prune);
1192 #if ENABLE_FEATURE_FIND_QUIT
1193 else if (parm == PARM_quit) {
1194 dbg("%d", __LINE__);
1195 (void) ALLOC_ACTION(quit);
1198 #if ENABLE_FEATURE_FIND_DELETE
1199 else if (parm == PARM_delete) {
1200 dbg("%d", __LINE__);
1202 G.recurse_flags |= ACTION_DEPTHFIRST;
1203 (void) ALLOC_ACTION(delete);
1206 #if ENABLE_FEATURE_FIND_EXEC
1207 else if (parm == PARM_exec) {
1210 IF_FEATURE_FIND_EXEC_PLUS(int all_subst = 0;)
1211 dbg("%d", __LINE__);
1213 ap = ALLOC_ACTION(exec);
1214 ap->exec_argv = ++argv; /* first arg after -exec */
1215 /*ap->exec_argc = 0; - ALLOC_ACTION did it */
1217 if (!*argv) /* did not see ';' or '+' until end */
1218 bb_error_msg_and_die(bb_msg_requires_arg, "-exec");
1219 // find -exec echo Foo ">{}<" ";"
1220 // executes "echo Foo >FILENAME<",
1221 // find -exec echo Foo ">{}<" "+"
1222 // executes "echo Foo FILENAME1 FILENAME2 FILENAME3...".
1223 if ((argv[0][0] == ';' || argv[0][0] == '+')
1224 && argv[0][1] == '\0'
1226 # if ENABLE_FEATURE_FIND_EXEC_PLUS
1227 if (argv[0][0] == '+')
1228 ap->filelist = xzalloc(sizeof(ap->filelist[0]));
1235 if (ap->exec_argc == 0)
1236 bb_error_msg_and_die(bb_msg_requires_arg, arg);
1237 ap->subst_count = xmalloc(ap->exec_argc * sizeof(int));
1240 ap->subst_count[i] = count_strstr(ap->exec_argv[i], "{}");
1241 IF_FEATURE_FIND_EXEC_PLUS(all_subst += ap->subst_count[i];)
1243 # if ENABLE_FEATURE_FIND_EXEC_PLUS
1245 * coreutils expects {} to appear only once in "-exec +"
1247 if (all_subst != 1 && ap->filelist)
1248 bb_simple_error_msg_and_die("only one '{}' allowed for -exec +");
1252 #if ENABLE_FEATURE_FIND_PAREN
1253 else if (parm == PARM_char_brace) {
1256 unsigned nested = 1;
1258 dbg("%d", __LINE__);
1262 bb_simple_error_msg_and_die("unpaired '('");
1263 if (LONE_CHAR(*endarg, '('))
1265 else if (LONE_CHAR(*endarg, ')') && !--nested) {
1270 ap = ALLOC_ACTION(paren);
1271 ap->subexpr = parse_params(argv + 1);
1272 *endarg = (char*) ")"; /* restore NULLed parameter */
1276 else if (parm == PARM_name || parm == PARM_iname) {
1278 dbg("%d", __LINE__);
1279 ap = ALLOC_ACTION(name);
1281 ap->iname = (parm == PARM_iname);
1283 #if ENABLE_FEATURE_FIND_PATH
1284 else if (parm == PARM_path IF_DESKTOP(|| parm == PARM_wholename) || parm == PARM_ipath) {
1286 dbg("%d", __LINE__);
1287 ap = ALLOC_ACTION(path);
1289 ap->ipath = (parm == PARM_ipath);
1292 #if ENABLE_FEATURE_FIND_REGEX
1293 else if (parm == PARM_regex) {
1295 dbg("%d", __LINE__);
1296 ap = ALLOC_ACTION(regex);
1297 xregcomp(&ap->compiled_pattern, arg1, 0 /*cflags*/);
1300 #if ENABLE_FEATURE_FIND_TYPE
1301 else if (parm == PARM_type) {
1303 ap = ALLOC_ACTION(type);
1304 ap->type_mask = find_type(arg1);
1305 dbg("created:type mask:%x", ap->type_mask);
1308 #if ENABLE_FEATURE_FIND_EXECUTABLE
1309 else if (parm == PARM_executable) {
1310 (void) ALLOC_ACTION(executable);
1313 #if ENABLE_FEATURE_FIND_PERM
1314 /* -perm BITS File's mode bits are exactly BITS (octal or symbolic).
1315 * Symbolic modes use mode 0 as a point of departure.
1316 * -perm -BITS All of the BITS are set in file's mode.
1317 * -perm [+/]BITS At least one of the BITS is set in file's mode.
1319 else if (parm == PARM_perm) {
1321 dbg("%d", __LINE__);
1322 ap = ALLOC_ACTION(perm);
1323 ap->perm_char = arg1[0];
1324 arg1 = (arg1[0] == '/' ? arg1+1 : plus_minus_num(arg1));
1325 /*ap->perm_mask = 0; - ALLOC_ACTION did it */
1326 ap->perm_mask = bb_parse_mode(arg1, ap->perm_mask);
1327 if (ap->perm_mask == (mode_t)-1)
1328 bb_error_msg_and_die("invalid mode '%s'", arg1);
1331 #if ENABLE_FEATURE_FIND_MTIME
1332 else if (parm == PARM_mtime) {
1334 dbg("%d", __LINE__);
1335 ap = ALLOC_ACTION(mtime);
1336 ap->mtime_char = arg1[0];
1337 ap->mtime_days = xatoul(plus_minus_num(arg1));
1340 #if ENABLE_FEATURE_FIND_MMIN
1341 else if (parm == PARM_mmin) {
1343 dbg("%d", __LINE__);
1344 ap = ALLOC_ACTION(mmin);
1345 ap->mmin_char = arg1[0];
1346 ap->mmin_mins = xatoul(plus_minus_num(arg1));
1349 #if ENABLE_FEATURE_FIND_NEWER
1350 else if (parm == PARM_newer) {
1351 struct stat stat_newer;
1353 dbg("%d", __LINE__);
1354 ap = ALLOC_ACTION(newer);
1355 xstat(arg1, &stat_newer);
1356 ap->newer_mtime = stat_newer.st_mtime;
1359 #if ENABLE_FEATURE_FIND_INUM
1360 else if (parm == PARM_inum) {
1362 dbg("%d", __LINE__);
1363 ap = ALLOC_ACTION(inum);
1364 ap->inode_num = xatoul(arg1);
1367 #if ENABLE_FEATURE_FIND_USER
1368 else if (parm == PARM_user) {
1370 dbg("%d", __LINE__);
1371 ap = ALLOC_ACTION(user);
1372 ap->uid = bb_strtou(arg1, NULL, 10);
1374 ap->uid = xuname2uid(arg1);
1377 #if ENABLE_FEATURE_FIND_GROUP
1378 else if (parm == PARM_group) {
1380 dbg("%d", __LINE__);
1381 ap = ALLOC_ACTION(group);
1382 ap->gid = bb_strtou(arg1, NULL, 10);
1384 ap->gid = xgroup2gid(arg1);
1387 #if ENABLE_FEATURE_FIND_SIZE
1388 else if (parm == PARM_size) {
1389 /* -size n[bckw]: file uses n units of space
1390 * b (default): units are 512-byte blocks
1396 #define XATOU_SFX xatoull_sfx
1398 #define XATOU_SFX xatoul_sfx
1400 static const struct suffix_mult find_suffixes[] = {
1409 dbg("%d", __LINE__);
1410 ap = ALLOC_ACTION(size);
1411 ap->size_char = arg1[0];
1412 ap->size = XATOU_SFX(plus_minus_num(arg1), find_suffixes);
1415 #if ENABLE_FEATURE_FIND_CONTEXT
1416 else if (parm == PARM_context) {
1418 dbg("%d", __LINE__);
1419 ap = ALLOC_ACTION(context);
1420 /*ap->context = NULL; - ALLOC_ACTION did it */
1421 /* SELinux headers erroneously declare non-const parameter */
1422 if (selinux_raw_to_trans_context((char*)arg1, &ap->context))
1423 bb_simple_perror_msg(arg1);
1426 #if ENABLE_FEATURE_FIND_LINKS
1427 else if (parm == PARM_links) {
1429 dbg("%d", __LINE__);
1430 ap = ALLOC_ACTION(links);
1431 ap->links_char = arg1[0];
1432 ap->links_count = xatoul(plus_minus_num(arg1));
1436 bb_error_msg("unrecognized: %s", arg);
1441 dbg("exiting %s", __func__);
1449 int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1450 int find_main(int argc UNUSED_PARAM, char **argv)
1453 char **past_HLP, *saved;
1457 /* "find -type f" + getopt("+HLP") => disaster.
1458 * Need to avoid getopt running into a non-HLP option.
1459 * Do this by temporarily storing NULL there:
1463 saved = *++past_HLP;
1466 if (saved[0] != '-')
1469 break; /* it is "-" */
1470 if (saved[1] == '-' && !saved[2]) {
1472 /* Try: find -- /dev/null */
1473 saved = *++past_HLP;
1476 if ((saved+1)[strspn(saved+1, "HLP")] != '\0')
1480 /* "+": stop on first non-option */
1481 i = getopt32(argv, "+HLP");
1483 G.recurse_flags |= ACTION_FOLLOWLINKS_L0 | ACTION_DANGLING_OK;
1485 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
1486 /* -P is default and is ignored */
1487 argv = past_HLP; /* same result as "argv += optind;" */
1490 for (firstopt = 0; argv[firstopt]; firstopt++) {
1491 if (argv[firstopt][0] == '-')
1493 if (ENABLE_FEATURE_FIND_NOT && LONE_CHAR(argv[firstopt], '!'))
1495 if (ENABLE_FEATURE_FIND_PAREN && LONE_CHAR(argv[firstopt], '('))
1498 if (firstopt == 0) {
1499 *--argv = (char*)".";
1503 G.actions = parse_params(&argv[firstopt]);
1504 argv[firstopt] = NULL;
1506 #if ENABLE_FEATURE_FIND_XDEV
1510 G.xdev_count = firstopt;
1511 G.xdev_dev = xzalloc(G.xdev_count * sizeof(G.xdev_dev[0]));
1512 for (i = 0; argv[i]; i++) {
1513 /* not xstat(): shouldn't bomb out on
1514 * "find not_exist exist -xdev" */
1515 if (stat(argv[i], &stbuf) == 0)
1516 G.xdev_dev[i] = stbuf.st_dev;
1517 /* else G.xdev_dev[i] stays 0 and
1518 * won't match any real device dev_t
1524 for (i = 0; argv[i]; i++) {
1525 if (!recursive_action(argv[i],
1526 G.recurse_flags,/* flags */
1527 fileAction, /* file action */
1528 fileAction, /* dir action */
1529 NULL, /* user data */
1532 G.exitstatus |= EXIT_FAILURE;
1536 IF_FEATURE_FIND_EXEC_PLUS(G.exitstatus |= flush_exec_plus();)
1537 return G.exitstatus;