blob: 9022867a214499134e00fbfcbef1138b5d51a929 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen17d49ef1999-10-06 20:25:32 +00002/*
3 * Mini find implementation for busybox
4 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Eric Andersenc4996011999-10-20 22:08:37 +00006 *
Matt Kraai096370d2001-02-07 03:52:38 +00007 * Reworked by David Douthitt <n9ubh@callsign.net> and
8 * Matt Kraai <kraai@alumni.carnegiemellon.edu>.
Eric Andersen17d49ef1999-10-06 20:25:32 +00009 *
Rob Landleye9a7a622006-09-22 02:52:41 +000010 * Licensed under the GPL version 2, see the file LICENSE in this tarball.
Eric Andersen17d49ef1999-10-06 20:25:32 +000011 */
12
Denis Vlasenkodf0553b2006-10-29 00:21:47 +000013/* findutils-4.1.20:
14 *
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' '{} {}' ';'
24 * file.txt file.txt
25 * (strace: execve("/bin/echo", ["echo", "file.txt file.txt"], [ 30 vars ]))
Denis Vlasenkodf0553b2006-10-29 00:21:47 +000026 * # find file.txt -exec 'echo' '{} {}' ';' -print -exec pwd ';'
27 * file.txt file.txt
28 * file.txt
29 * /tmp
Denis Vlasenkoe2fb7192006-10-29 19:03:56 +000030 * # find -name '*.c' -o -name '*.h'
31 * [shows files, *.c and *.h intermixed]
Denis Vlasenko5d499e12006-10-29 19:07:01 +000032 * # find file.txt -name '*f*' -o -name '*t*'
33 * file.txt
34 * # find file.txt -name '*z*' -o -name '*t*'
35 * file.txt
36 * # find file.txt -name '*f*' -o -name '*z*'
37 * file.txt
Denis Vlasenkoa3b4fed2006-10-31 03:20:13 +000038 *
39 * # find t z -name '*t*' -print -o -name '*z*'
40 * t
41 * # find t z t z -name '*t*' -o -name '*z*' -print
42 * z
43 * z
44 * # find t z t z '(' -name '*t*' -o -name '*z*' ')' -o -print
45 * (no output)
Denis Vlasenkodf0553b2006-10-29 00:21:47 +000046 */
47
Denis Vlasenko53a0e972007-06-16 00:30:52 +000048/* Testing script
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
54 */
55
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020056//kbuild:lib-$(CONFIG_FIND) += find.o
57//config:
58//config:config FIND
59//config: bool "find"
60//config: default n
61//config: help
62//config: find is used to search your system to find specified files.
63//config:
64//config:config FEATURE_FIND_PRINT0
65//config: bool "Enable -print0: NUL-terminated output"
66//config: default y
67//config: depends on FIND
68//config: help
69//config: Causes output names to be separated by a NUL character
70//config: rather than a newline. This allows names that contain
71//config: newlines and other whitespace to be more easily
72//config: interpreted by other programs.
73//config:
74//config:config FEATURE_FIND_MTIME
75//config: bool "Enable -mtime: modified time matching"
76//config: default y
77//config: depends on FIND
78//config: help
79//config: Allow searching based on the modification time of
80//config: files, in days.
81//config:
82//config:config FEATURE_FIND_MMIN
83//config: bool "Enable -mmin: modified time matching by minutes"
84//config: default y
85//config: depends on FIND
86//config: help
87//config: Allow searching based on the modification time of
88//config: files, in minutes.
89//config:
90//config:config FEATURE_FIND_PERM
91//config: bool "Enable -perm: permissions matching"
92//config: default y
93//config: depends on FIND
94//config: help
95//config: Enable searching based on file permissions.
96//config:
97//config:config FEATURE_FIND_TYPE
98//config: bool "Enable -type: file type matching (file/dir/link/...)"
99//config: default y
100//config: depends on FIND
101//config: help
102//config: Enable searching based on file type (file,
103//config: directory, socket, device, etc.).
104//config:
105//config:config FEATURE_FIND_XDEV
106//config: bool "Enable -xdev: 'stay in filesystem'"
107//config: default y
108//config: depends on FIND
109//config: help
110//config: This option allows find to restrict searches to a single filesystem.
111//config:
112//config:config FEATURE_FIND_MAXDEPTH
113//config: bool "Enable -maxdepth N"
114//config: default y
115//config: depends on FIND
116//config: help
117//config: This option enables -maxdepth N option.
118//config:
119//config:config FEATURE_FIND_NEWER
120//config: bool "Enable -newer: compare file modification times"
121//config: default y
122//config: depends on FIND
123//config: help
124//config: Support the 'find -newer' option for finding any files which have
125//config: a modified time that is more recent than the specified FILE.
126//config:
127//config:config FEATURE_FIND_INUM
128//config: bool "Enable -inum: inode number matching"
129//config: default y
130//config: depends on FIND
131//config: help
132//config: Support the 'find -inum' option for searching by inode number.
133//config:
134//config:config FEATURE_FIND_EXEC
135//config: bool "Enable -exec: execute commands"
136//config: default y
137//config: depends on FIND
138//config: help
139//config: Support the 'find -exec' option for executing commands based upon
140//config: the files matched.
141//config:
142//config:config FEATURE_FIND_USER
143//config: bool "Enable -user: username/uid matching"
144//config: default y
145//config: depends on FIND
146//config: help
147//config: Support the 'find -user' option for searching by username or uid.
148//config:
149//config:config FEATURE_FIND_GROUP
150//config: bool "Enable -group: group/gid matching"
151//config: default y
152//config: depends on FIND
153//config: help
154//config: Support the 'find -group' option for searching by group name or gid.
155//config:
156//config:config FEATURE_FIND_NOT
157//config: bool "Enable the 'not' (!) operator"
158//config: default y
159//config: depends on FIND
160//config: help
161//config: Support the '!' operator to invert the test results.
162//config: If 'Enable full-blown desktop' is enabled, then will also support
163//config: the non-POSIX notation '-not'.
164//config:
165//config:config FEATURE_FIND_DEPTH
166//config: bool "Enable -depth"
167//config: default y
168//config: depends on FIND
169//config: help
170//config: Process each directory's contents before the directory itself.
171//config:
172//config:config FEATURE_FIND_PAREN
173//config: bool "Enable parens in options"
174//config: default y
175//config: depends on FIND
176//config: help
177//config: Enable usage of parens '(' to specify logical order of arguments.
178//config:
179//config:config FEATURE_FIND_SIZE
180//config: bool "Enable -size: file size matching"
181//config: default y
182//config: depends on FIND
183//config: help
184//config: Support the 'find -size' option for searching by file size.
185//config:
186//config:config FEATURE_FIND_PRUNE
187//config: bool "Enable -prune: exclude subdirectories"
188//config: default y
189//config: depends on FIND
190//config: help
191//config: If the file is a directory, dont descend into it. Useful for
192//config: exclusion .svn and CVS directories.
193//config:
194//config:config FEATURE_FIND_DELETE
195//config: bool "Enable -delete: delete files/dirs"
196//config: default n
197//config: depends on FIND && FEATURE_FIND_DEPTH
198//config: help
199//config: Support the 'find -delete' option for deleting files and directories.
200//config: WARNING: This option can do much harm if used wrong. Busybox will not
201//config: try to protect the user from doing stupid things. Use with care.
202//config:
203//config:config FEATURE_FIND_PATH
204//config: bool "Enable -path: match pathname with shell pattern"
205//config: default y
206//config: depends on FIND
207//config: help
208//config: The -path option matches whole pathname instead of just filename.
209//config:
210//config:config FEATURE_FIND_REGEX
211//config: bool "Enable -regex: match pathname with regex"
212//config: default y
213//config: depends on FIND
214//config: help
215//config: The -regex option matches whole pathname against regular expression.
216//config:
217//config:config FEATURE_FIND_CONTEXT
218//config: bool "Enable -context: security context matching"
219//config: default n
220//config: depends on FIND && SELINUX
221//config: help
222//config: Support the 'find -context' option for matching security context.
223//config:
224//config:config FEATURE_FIND_LINKS
225//config: bool "Enable -links: link count matching"
226//config: default n
227//config: depends on FIND
228//config: help
229//config: Support the 'find -links' option for matching number of links.
230
Matt Kraai096370d2001-02-07 03:52:38 +0000231#include <fnmatch.h>
Denis Vlasenkob6adbf12007-05-26 19:00:18 +0000232#include "libbb.h"
Denis Vlasenkob9411292007-06-15 23:43:11 +0000233#if ENABLE_FEATURE_FIND_REGEX
234#include "xregex.h"
235#endif
Eric Andersen17d49ef1999-10-06 20:25:32 +0000236
Denis Vlasenko99912ca2007-04-10 15:43:37 +0000237/* This is a NOEXEC applet. Be very careful! */
238
239
Denys Vlasenko6c750f12009-09-27 01:51:47 +0200240typedef int (*action_fp)(const char *fileName, const struct stat *statbuf, void *) FAST_FUNC;
Matt Kraai096370d2001-02-07 03:52:38 +0000241
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000242typedef struct {
243 action_fp f;
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000244#if ENABLE_FEATURE_FIND_NOT
Bernhard Reutner-Fischer32773ac2007-03-29 13:54:17 +0000245 bool invert;
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000246#endif
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000247} action;
Denys Vlasenkod5f1b1b2009-06-05 12:06:05 +0200248
Denys Vlasenko606291b2009-09-23 23:15:43 +0200249#define ACTS(name, ...) typedef struct { action a; __VA_ARGS__ } action_##name;
Denys Vlasenkod5f1b1b2009-06-05 12:06:05 +0200250#define ACTF(name) \
251 static int FAST_FUNC func_##name(const char *fileName UNUSED_PARAM, \
Denys Vlasenko6c750f12009-09-27 01:51:47 +0200252 const struct stat *statbuf UNUSED_PARAM, \
Denys Vlasenkod5f1b1b2009-06-05 12:06:05 +0200253 action_##name* ap UNUSED_PARAM)
254
255 ACTS(print)
256 ACTS(name, const char *pattern; bool iname;)
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000257IF_FEATURE_FIND_PATH( ACTS(path, const char *pattern;))
258IF_FEATURE_FIND_REGEX( ACTS(regex, regex_t compiled_pattern;))
259IF_FEATURE_FIND_PRINT0( ACTS(print0))
260IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;))
261IF_FEATURE_FIND_PERM( ACTS(perm, char perm_char; mode_t perm_mask;))
262IF_FEATURE_FIND_MTIME( ACTS(mtime, char mtime_char; unsigned mtime_days;))
263IF_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; unsigned mmin_mins;))
264IF_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;))
265IF_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;))
266IF_FEATURE_FIND_USER( ACTS(user, uid_t uid;))
267IF_FEATURE_FIND_SIZE( ACTS(size, char size_char; off_t size;))
268IF_FEATURE_FIND_CONTEXT(ACTS(context, security_context_t context;))
269IF_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
270IF_FEATURE_FIND_PRUNE( ACTS(prune))
271IF_FEATURE_FIND_DELETE( ACTS(delete))
272IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;))
273IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
Matheus Izvekovd0f601f2010-01-06 09:19:04 +0100274IF_FEATURE_FIND_LINKS( ACTS(links, char links_char; int links_count;))
Matt Kraai096370d2001-02-07 03:52:38 +0000275
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200276struct globals {
277 IF_FEATURE_FIND_XDEV(dev_t *xdev_dev;)
278 IF_FEATURE_FIND_XDEV(int xdev_count;)
279 action ***actions;
280 bool need_print;
281 recurse_flags_t recurse_flags;
Denys Vlasenko98a4c7c2010-02-04 15:00:15 +0100282} FIX_ALIASING;
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200283#define G (*(struct globals*)&bb_common_bufsiz1)
284#define INIT_G() do { \
285 struct G_sizecheck { \
286 char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \
287 }; \
Denys Vlasenko1b34d4f2009-09-30 02:39:57 +0200288 /* we have to zero it out because of NOEXEC */ \
289 memset(&G, 0, offsetof(struct globals, need_print)); \
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200290 G.need_print = 1; \
291 G.recurse_flags = ACTION_RECURSE; \
292} while (0)
Rob Landley5d3a0e82005-10-04 03:34:39 +0000293
Denis Vlasenko666da5e2006-12-26 18:17:42 +0000294#if ENABLE_FEATURE_FIND_EXEC
Denis Vlasenkobbd695d2007-04-08 10:52:28 +0000295static unsigned count_subst(const char *str)
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000296{
Denis Vlasenkobbd695d2007-04-08 10:52:28 +0000297 unsigned count = 0;
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000298 while ((str = strstr(str, "{}")) != NULL) {
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000299 count++;
300 str++;
301 }
302 return count;
303}
304
305
Denis Vlasenkobbd695d2007-04-08 10:52:28 +0000306static char* subst(const char *src, unsigned count, const char* filename)
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000307{
308 char *buf, *dst, *end;
Bernhard Reutner-Fischer32773ac2007-03-29 13:54:17 +0000309 size_t flen = strlen(filename);
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000310 /* we replace each '{}' with filename: growth by strlen-2 */
311 buf = dst = xmalloc(strlen(src) + count*(flen-2) + 1);
312 while ((end = strstr(src, "{}"))) {
313 memcpy(dst, src, end - src);
314 dst += end - src;
315 src = end + 2;
316 memcpy(dst, filename, flen);
317 dst += flen;
318 }
319 strcpy(dst, src);
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000320 return buf;
321}
Denis Vlasenko666da5e2006-12-26 18:17:42 +0000322#endif
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000323
Denis Vlasenkobbd695d2007-04-08 10:52:28 +0000324/* Return values of ACTFs ('action functions') are a bit mask:
325 * bit 1=1: prune (use SKIP constant for setting it)
326 * bit 0=1: matched successfully (TRUE)
327 */
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000328
Denys Vlasenko6c750f12009-09-27 01:51:47 +0200329static int exec_actions(action ***appp, const char *fileName, const struct stat *statbuf)
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000330{
331 int cur_group;
332 int cur_action;
Denis Vlasenkob04b4352007-04-08 11:10:43 +0000333 int rc = 0;
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000334 action **app, *ap;
335
Denis Vlasenkob04b4352007-04-08 11:10:43 +0000336 /* "action group" is a set of actions ANDed together.
337 * groups are ORed together.
338 * We simply evaluate each group until we find one in which all actions
339 * succeed. */
340
341 /* -prune is special: if it is encountered, then we won't
342 * descend into current directory. It doesn't matter whether
343 * action group (in which -prune sits) will succeed or not:
344 * find * -prune -name 'f*' -o -name 'm*' -- prunes every dir
345 * find * -name 'f*' -o -prune -name 'm*' -- prunes all dirs
346 * not starting with 'f' */
347
348 /* We invert TRUE bit (bit 0). Now 1 there means 'failure'.
349 * and bitwise OR in "rc |= TRUE ^ ap->f()" will:
350 * (1) make SKIP (-prune) bit stick; and (2) detect 'failure'.
351 * On return, bit is restored. */
352
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000353 cur_group = -1;
Matheus Izvekovd0f601f2010-01-06 09:19:04 +0100354 while ((app = appp[++cur_group]) != NULL) {
Denis Vlasenkob04b4352007-04-08 11:10:43 +0000355 rc &= ~TRUE; /* 'success' so far, clear TRUE bit */
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000356 cur_action = -1;
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000357 while (1) {
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000358 ap = app[++cur_action];
Denis Vlasenkobbd695d2007-04-08 10:52:28 +0000359 if (!ap) /* all actions in group were successful */
Denis Vlasenkob04b4352007-04-08 11:10:43 +0000360 return rc ^ TRUE; /* restore TRUE bit */
Denis Vlasenkobbd695d2007-04-08 10:52:28 +0000361 rc |= TRUE ^ ap->f(fileName, statbuf, ap);
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000362#if ENABLE_FEATURE_FIND_NOT
Denis Vlasenkobbd695d2007-04-08 10:52:28 +0000363 if (ap->invert) rc ^= TRUE;
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000364#endif
Denis Vlasenkobbd695d2007-04-08 10:52:28 +0000365 if (rc & TRUE) /* current group failed, try next */
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000366 break;
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000367 }
368 }
Denis Vlasenkob04b4352007-04-08 11:10:43 +0000369 return rc ^ TRUE; /* restore TRUE bit */
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000370}
371
372
Denis Vlasenko92258542006-11-01 10:25:35 +0000373ACTF(name)
Eric Andersen17d49ef1999-10-06 20:25:32 +0000374{
Denis Vlasenkodc757aa2007-06-30 08:04:05 +0000375 const char *tmp = bb_basename(fileName);
Denys Vlasenko91388172010-04-26 09:54:04 +0200376 if (tmp != fileName && *tmp == '\0') {
377 /* "foo/bar/". Oh no... go back to 'b' */
Denis Vlasenkodc757aa2007-06-30 08:04:05 +0000378 tmp--;
379 while (tmp != fileName && *--tmp != '/')
380 continue;
381 if (*tmp == '/')
382 tmp++;
Denis Vlasenkobbd695d2007-04-08 10:52:28 +0000383 }
Denys Vlasenko91388172010-04-26 09:54:04 +0200384 /* Was using FNM_PERIOD flag too,
385 * but somewhere between 4.1.20 and 4.4.0 GNU find stopped using it.
386 * find -name '*foo' should match .foo too:
387 */
388 return fnmatch(ap->pattern, tmp, (ap->iname ? FNM_CASEFOLD : 0)) == 0;
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000389}
Denis Vlasenko75aa6152007-12-09 10:07:39 +0000390
Denis Vlasenkob9411292007-06-15 23:43:11 +0000391#if ENABLE_FEATURE_FIND_PATH
392ACTF(path)
393{
394 return fnmatch(ap->pattern, fileName, 0) == 0;
395}
396#endif
397#if ENABLE_FEATURE_FIND_REGEX
398ACTF(regex)
399{
400 regmatch_t match;
401 if (regexec(&ap->compiled_pattern, fileName, 1, &match, 0 /*eflags*/))
402 return 0; /* no match */
403 if (match.rm_so)
404 return 0; /* match doesn't start at pos 0 */
405 if (fileName[match.rm_eo])
406 return 0; /* match doesn't end exactly at end of pathname */
407 return 1;
408}
409#endif
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000410#if ENABLE_FEATURE_FIND_TYPE
Denis Vlasenko92258542006-11-01 10:25:35 +0000411ACTF(type)
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000412{
Denis Vlasenko31c65f22006-10-31 23:39:37 +0000413 return ((statbuf->st_mode & S_IFMT) == ap->type_mask);
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000414}
Rob Landleycee605c2005-10-06 16:39:17 +0000415#endif
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000416#if ENABLE_FEATURE_FIND_PERM
Denis Vlasenko92258542006-11-01 10:25:35 +0000417ACTF(perm)
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000418{
Denis Vlasenkofc7f9222007-01-26 23:00:05 +0000419 /* -perm +mode: at least one of perm_mask bits are set */
420 if (ap->perm_char == '+')
421 return (statbuf->st_mode & ap->perm_mask) != 0;
422 /* -perm -mode: all of perm_mask are set */
423 if (ap->perm_char == '-')
424 return (statbuf->st_mode & ap->perm_mask) == ap->perm_mask;
425 /* -perm mode: file mode must match perm_mask */
426 return (statbuf->st_mode & 07777) == ap->perm_mask;
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000427}
Rob Landleycee605c2005-10-06 16:39:17 +0000428#endif
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000429#if ENABLE_FEATURE_FIND_MTIME
Denis Vlasenko92258542006-11-01 10:25:35 +0000430ACTF(mtime)
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000431{
432 time_t file_age = time(NULL) - statbuf->st_mtime;
Denis Vlasenkofc7f9222007-01-26 23:00:05 +0000433 time_t mtime_secs = ap->mtime_days * 24*60*60;
434 if (ap->mtime_char == '+')
435 return file_age >= mtime_secs + 24*60*60;
436 if (ap->mtime_char == '-')
437 return file_age < mtime_secs;
438 /* just numeric mtime */
439 return file_age >= mtime_secs && file_age < (mtime_secs + 24*60*60);
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000440}
Rob Landleycee605c2005-10-06 16:39:17 +0000441#endif
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000442#if ENABLE_FEATURE_FIND_MMIN
Denis Vlasenko92258542006-11-01 10:25:35 +0000443ACTF(mmin)
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000444{
445 time_t file_age = time(NULL) - statbuf->st_mtime;
446 time_t mmin_secs = ap->mmin_mins * 60;
Denis Vlasenkofc7f9222007-01-26 23:00:05 +0000447 if (ap->mmin_char == '+')
448 return file_age >= mmin_secs + 60;
449 if (ap->mmin_char == '-')
450 return file_age < mmin_secs;
451 /* just numeric mmin */
452 return file_age >= mmin_secs && file_age < (mmin_secs + 60);
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000453}
Paul Fox72d1a232006-01-13 21:05:41 +0000454#endif
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000455#if ENABLE_FEATURE_FIND_NEWER
Denis Vlasenko92258542006-11-01 10:25:35 +0000456ACTF(newer)
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000457{
Denis Vlasenkofc7f9222007-01-26 23:00:05 +0000458 return (ap->newer_mtime < statbuf->st_mtime);
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000459}
Rob Landleycee605c2005-10-06 16:39:17 +0000460#endif
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000461#if ENABLE_FEATURE_FIND_INUM
Denis Vlasenko92258542006-11-01 10:25:35 +0000462ACTF(inum)
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000463{
Denis Vlasenkofc7f9222007-01-26 23:00:05 +0000464 return (statbuf->st_ino == ap->inode_num);
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000465}
Rob Landleycee605c2005-10-06 16:39:17 +0000466#endif
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000467#if ENABLE_FEATURE_FIND_EXEC
Denis Vlasenko92258542006-11-01 10:25:35 +0000468ACTF(exec)
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000469{
470 int i, rc;
Denys Vlasenkoaa7da732009-09-13 14:57:24 +0200471#if ENABLE_USE_PORTABLE_CODE
472 char **argv = alloca(sizeof(char*) * (ap->exec_argc + 1));
473#else /* gcc 4.3.1 generates smaller code: */
Denis Vlasenkocd7001f2007-04-09 21:32:30 +0000474 char *argv[ap->exec_argc + 1];
Denys Vlasenkoaa7da732009-09-13 14:57:24 +0200475#endif
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000476 for (i = 0; i < ap->exec_argc; i++)
477 argv[i] = subst(ap->exec_argv[i], ap->subst_count[i], fileName);
478 argv[i] = NULL; /* terminate the list */
Denis Vlasenko7e754f12007-04-09 13:04:50 +0000479
Denis Vlasenkocd7001f2007-04-09 21:32:30 +0000480 rc = spawn_and_wait(argv);
Denis Vlasenko7e754f12007-04-09 13:04:50 +0000481 if (rc < 0)
Denis Vlasenko0c97c9d2007-10-01 11:58:38 +0000482 bb_simple_perror_msg(argv[0]);
Denis Vlasenkocd7001f2007-04-09 21:32:30 +0000483
484 i = 0;
485 while (argv[i])
486 free(argv[i++]);
487 return rc == 0; /* return 1 if exitcode 0 */
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000488}
Rob Landleycee605c2005-10-06 16:39:17 +0000489#endif
Denis Vlasenkoa1007072007-02-02 01:17:52 +0000490#if ENABLE_FEATURE_FIND_USER
491ACTF(user)
492{
493 return (statbuf->st_uid == ap->uid);
494}
495#endif
Denis Vlasenko56fce002007-04-04 23:41:35 +0000496#if ENABLE_FEATURE_FIND_GROUP
497ACTF(group)
498{
499 return (statbuf->st_gid == ap->gid);
500}
501#endif
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000502#if ENABLE_FEATURE_FIND_PRINT0
Denis Vlasenko92258542006-11-01 10:25:35 +0000503ACTF(print0)
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000504{
505 printf("%s%c", fileName, '\0');
Denis Vlasenko3a6755f2006-10-14 14:24:30 +0000506 return TRUE;
Eric Andersen17d49ef1999-10-06 20:25:32 +0000507}
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000508#endif
Denis Vlasenko92258542006-11-01 10:25:35 +0000509ACTF(print)
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000510{
511 puts(fileName);
512 return TRUE;
513}
Denis Vlasenko56fce002007-04-04 23:41:35 +0000514#if ENABLE_FEATURE_FIND_PAREN
Denis Vlasenko92258542006-11-01 10:25:35 +0000515ACTF(paren)
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000516{
517 return exec_actions(ap->subexpr, fileName, statbuf);
518}
Denis Vlasenko56fce002007-04-04 23:41:35 +0000519#endif
Denis Vlasenkob9411292007-06-15 23:43:11 +0000520#if ENABLE_FEATURE_FIND_SIZE
521ACTF(size)
522{
Denis Vlasenko53a0e972007-06-16 00:30:52 +0000523 if (ap->size_char == '+')
524 return statbuf->st_size > ap->size;
525 if (ap->size_char == '-')
526 return statbuf->st_size < ap->size;
Denis Vlasenkob9411292007-06-15 23:43:11 +0000527 return statbuf->st_size == ap->size;
528}
529#endif
Bernhard Reutner-Fischer6d79dd62007-04-05 09:40:12 +0000530#if ENABLE_FEATURE_FIND_PRUNE
Denis Vlasenko5f18e7c2006-10-31 03:21:02 +0000531/*
532 * -prune: if -depth is not given, return true and do not descend
533 * current dir; if -depth is given, return false with no effect.
534 * Example:
535 * find dir -name 'asm-*' -prune -o -name '*.[chS]' -print
536 */
Denis Vlasenko92258542006-11-01 10:25:35 +0000537ACTF(prune)
Denis Vlasenko5f18e7c2006-10-31 03:21:02 +0000538{
Denis Vlasenkobbd695d2007-04-08 10:52:28 +0000539 return SKIP + TRUE;
Denis Vlasenko5f18e7c2006-10-31 03:21:02 +0000540}
Denis Vlasenko56fce002007-04-04 23:41:35 +0000541#endif
Denis Vlasenko62f04792007-04-13 10:00:12 +0000542#if ENABLE_FEATURE_FIND_DELETE
543ACTF(delete)
544{
545 int rc;
546 if (S_ISDIR(statbuf->st_mode)) {
547 rc = rmdir(fileName);
548 } else {
549 rc = unlink(fileName);
550 }
551 if (rc < 0)
Denis Vlasenko0c97c9d2007-10-01 11:58:38 +0000552 bb_simple_perror_msg(fileName);
Denis Vlasenko62f04792007-04-13 10:00:12 +0000553 return TRUE;
554}
555#endif
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000556#if ENABLE_FEATURE_FIND_CONTEXT
557ACTF(context)
558{
559 security_context_t con;
560 int rc;
561
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200562 if (G.recurse_flags & ACTION_FOLLOWLINKS) {
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000563 rc = getfilecon(fileName, &con);
564 } else {
565 rc = lgetfilecon(fileName, &con);
566 }
567 if (rc < 0)
568 return FALSE;
569 rc = strcmp(ap->context, con);
570 freecon(con);
571 return rc == 0;
572}
573#endif
Matheus Izvekovd0f601f2010-01-06 09:19:04 +0100574#if ENABLE_FEATURE_FIND_LINKS
575ACTF(links)
576{
577 switch(ap->links_char) {
578 case '-' : return (statbuf->st_nlink < ap->links_count);
579 case '+' : return (statbuf->st_nlink > ap->links_count);
580 default: return (statbuf->st_nlink == ap->links_count);
581 }
582}
583#endif
Denis Vlasenko62f04792007-04-13 10:00:12 +0000584
Denis Vlasenkodefc1ea2008-06-27 02:52:20 +0000585static int FAST_FUNC fileAction(const char *fileName,
Denis Vlasenko85c24712008-03-17 09:04:04 +0000586 struct stat *statbuf,
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000587 void *userData IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM),
588 int depth IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM))
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000589{
Denys Vlasenkoce9b97f2010-01-10 02:33:02 +0100590 int r;
Denis Vlasenkob9411292007-06-15 23:43:11 +0000591#if ENABLE_FEATURE_FIND_MAXDEPTH
Denis Vlasenko83518d12009-03-20 22:17:13 +0000592#define minmaxdepth ((int*)userData)
Denis Vlasenkob9411292007-06-15 23:43:11 +0000593
Denys Vlasenkoce9b97f2010-01-10 02:33:02 +0100594 if (depth < minmaxdepth[0])
595 return TRUE; /* skip this, continue recursing */
596 if (depth > minmaxdepth[1])
597 return SKIP; /* stop recursing */
Denis Vlasenkob9411292007-06-15 23:43:11 +0000598#endif
599
Denys Vlasenkoce9b97f2010-01-10 02:33:02 +0100600 r = exec_actions(G.actions, fileName, statbuf);
601 /* Had no explicit -print[0] or -exec? then print */
602 if ((r & TRUE) && G.need_print)
603 puts(fileName);
604
605#if ENABLE_FEATURE_FIND_MAXDEPTH
606 if (S_ISDIR(statbuf->st_mode)) {
607 if (depth == minmaxdepth[1])
608 return SKIP;
609 }
610#endif
Denis Vlasenkobbd695d2007-04-08 10:52:28 +0000611#if ENABLE_FEATURE_FIND_XDEV
Denys Vlasenkoce9b97f2010-01-10 02:33:02 +0100612 /* -xdev stops on mountpoints, but AFTER mountpoit itself
613 * is processed as usual */
Denys Vlasenko6c750f12009-09-27 01:51:47 +0200614 if (S_ISDIR(statbuf->st_mode)) {
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200615 if (G.xdev_count) {
Denys Vlasenkoce9b97f2010-01-10 02:33:02 +0100616 int i;
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200617 for (i = 0; i < G.xdev_count; i++) {
618 if (G.xdev_dev[i] == statbuf->st_dev)
Denys Vlasenko6c750f12009-09-27 01:51:47 +0200619 goto found;
620 }
Paul Foxdcf9bba2007-09-06 17:45:16 +0000621 return SKIP;
Denys Vlasenko6c750f12009-09-27 01:51:47 +0200622 found: ;
623 }
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000624 }
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000625#endif
Denys Vlasenko6c750f12009-09-27 01:51:47 +0200626
Denis Vlasenko5f18e7c2006-10-31 03:21:02 +0000627 /* Cannot return 0: our caller, recursive_action(),
628 * will perror() and skip dirs (if called on dir) */
Denys Vlasenkoce9b97f2010-01-10 02:33:02 +0100629 return (r & SKIP) ? SKIP : TRUE;
Denys Vlasenko6c750f12009-09-27 01:51:47 +0200630#undef minmaxdepth
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000631}
632
Eric Andersen17d49ef1999-10-06 20:25:32 +0000633
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000634#if ENABLE_FEATURE_FIND_TYPE
Denis Vlasenko434ad542007-01-27 13:45:17 +0000635static int find_type(const char *type)
Matt Kraai096370d2001-02-07 03:52:38 +0000636{
637 int mask = 0;
638
Bernhard Reutner-Fischer307d27d2007-03-29 13:56:02 +0000639 if (*type == 'b')
Denis Vlasenko3a6755f2006-10-14 14:24:30 +0000640 mask = S_IFBLK;
Bernhard Reutner-Fischer307d27d2007-03-29 13:56:02 +0000641 else if (*type == 'c')
Denis Vlasenko3a6755f2006-10-14 14:24:30 +0000642 mask = S_IFCHR;
Bernhard Reutner-Fischer307d27d2007-03-29 13:56:02 +0000643 else if (*type == 'd')
Denis Vlasenko3a6755f2006-10-14 14:24:30 +0000644 mask = S_IFDIR;
Bernhard Reutner-Fischer307d27d2007-03-29 13:56:02 +0000645 else if (*type == 'p')
Denis Vlasenko3a6755f2006-10-14 14:24:30 +0000646 mask = S_IFIFO;
Bernhard Reutner-Fischer307d27d2007-03-29 13:56:02 +0000647 else if (*type == 'f')
Denis Vlasenko3a6755f2006-10-14 14:24:30 +0000648 mask = S_IFREG;
Bernhard Reutner-Fischer307d27d2007-03-29 13:56:02 +0000649 else if (*type == 'l')
Denis Vlasenko3a6755f2006-10-14 14:24:30 +0000650 mask = S_IFLNK;
Bernhard Reutner-Fischer307d27d2007-03-29 13:56:02 +0000651 else if (*type == 's')
Denis Vlasenko3a6755f2006-10-14 14:24:30 +0000652 mask = S_IFSOCK;
Matt Kraai096370d2001-02-07 03:52:38 +0000653
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200654 if (mask == 0 || type[1] != '\0')
Bernhard Reutner-Fischer19008b82006-06-07 20:17:41 +0000655 bb_error_msg_and_die(bb_msg_invalid_arg, type, "-type");
Matt Kraai096370d2001-02-07 03:52:38 +0000656
657 return mask;
658}
659#endif
660
Denis Vlasenko4b9b0ce2007-07-01 17:35:17 +0000661#if ENABLE_FEATURE_FIND_PERM \
662 || ENABLE_FEATURE_FIND_MTIME || ENABLE_FEATURE_FIND_MMIN \
Matheus Izvekovd0f601f2010-01-06 09:19:04 +0100663 || ENABLE_FEATURE_FIND_SIZE || ENABLE_FEATURE_FIND_LINKS
Denis Vlasenkofc7f9222007-01-26 23:00:05 +0000664static const char* plus_minus_num(const char* str)
665{
666 if (*str == '-' || *str == '+')
667 str++;
668 return str;
669}
Denis Vlasenko4c978632007-02-03 03:31:13 +0000670#endif
Denis Vlasenkofc7f9222007-01-26 23:00:05 +0000671
Denis Vlasenko769d1e02007-01-22 23:04:27 +0000672static action*** parse_params(char **argv)
Eric Andersen17d49ef1999-10-06 20:25:32 +0000673{
Denis Vlasenko56fce002007-04-04 23:41:35 +0000674 enum {
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200675 PARM_a ,
676 PARM_o ,
677 IF_FEATURE_FIND_NOT( PARM_char_not ,)
Denis Vlasenko56fce002007-04-04 23:41:35 +0000678#if ENABLE_DESKTOP
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200679 PARM_and ,
680 PARM_or ,
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000681 IF_FEATURE_FIND_NOT( PARM_not ,)
Denis Vlasenko56fce002007-04-04 23:41:35 +0000682#endif
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200683 PARM_print ,
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000684 IF_FEATURE_FIND_PRINT0( PARM_print0 ,)
685 IF_FEATURE_FIND_DEPTH( PARM_depth ,)
686 IF_FEATURE_FIND_PRUNE( PARM_prune ,)
687 IF_FEATURE_FIND_DELETE( PARM_delete ,)
688 IF_FEATURE_FIND_EXEC( PARM_exec ,)
689 IF_FEATURE_FIND_PAREN( PARM_char_brace,)
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000690 /* All options starting from here require argument */
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200691 PARM_name ,
692 PARM_iname ,
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000693 IF_FEATURE_FIND_PATH( PARM_path ,)
694 IF_FEATURE_FIND_REGEX( PARM_regex ,)
695 IF_FEATURE_FIND_TYPE( PARM_type ,)
696 IF_FEATURE_FIND_PERM( PARM_perm ,)
697 IF_FEATURE_FIND_MTIME( PARM_mtime ,)
698 IF_FEATURE_FIND_MMIN( PARM_mmin ,)
699 IF_FEATURE_FIND_NEWER( PARM_newer ,)
700 IF_FEATURE_FIND_INUM( PARM_inum ,)
701 IF_FEATURE_FIND_USER( PARM_user ,)
702 IF_FEATURE_FIND_GROUP( PARM_group ,)
703 IF_FEATURE_FIND_SIZE( PARM_size ,)
704 IF_FEATURE_FIND_CONTEXT(PARM_context ,)
Matheus Izvekovd0f601f2010-01-06 09:19:04 +0100705 IF_FEATURE_FIND_LINKS( PARM_links ,)
Denis Vlasenko56fce002007-04-04 23:41:35 +0000706 };
707
Denis Vlasenko6ca409e2007-08-12 20:58:27 +0000708 static const char params[] ALIGN1 =
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000709 "-a\0"
710 "-o\0"
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000711 IF_FEATURE_FIND_NOT( "!\0" )
Denis Vlasenko56fce002007-04-04 23:41:35 +0000712#if ENABLE_DESKTOP
Denis Vlasenko319f8eb2007-08-13 11:09:30 +0000713 "-and\0"
714 "-or\0"
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000715 IF_FEATURE_FIND_NOT( "-not\0" )
Denis Vlasenko56fce002007-04-04 23:41:35 +0000716#endif
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000717 "-print\0"
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000718 IF_FEATURE_FIND_PRINT0( "-print0\0" )
719 IF_FEATURE_FIND_DEPTH( "-depth\0" )
720 IF_FEATURE_FIND_PRUNE( "-prune\0" )
721 IF_FEATURE_FIND_DELETE( "-delete\0" )
722 IF_FEATURE_FIND_EXEC( "-exec\0" )
723 IF_FEATURE_FIND_PAREN( "(\0" )
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000724 /* All options starting from here require argument */
Denis Vlasenko319f8eb2007-08-13 11:09:30 +0000725 "-name\0"
Denis Vlasenko75aa6152007-12-09 10:07:39 +0000726 "-iname\0"
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000727 IF_FEATURE_FIND_PATH( "-path\0" )
728 IF_FEATURE_FIND_REGEX( "-regex\0" )
729 IF_FEATURE_FIND_TYPE( "-type\0" )
730 IF_FEATURE_FIND_PERM( "-perm\0" )
731 IF_FEATURE_FIND_MTIME( "-mtime\0" )
732 IF_FEATURE_FIND_MMIN( "-mmin\0" )
733 IF_FEATURE_FIND_NEWER( "-newer\0" )
734 IF_FEATURE_FIND_INUM( "-inum\0" )
735 IF_FEATURE_FIND_USER( "-user\0" )
736 IF_FEATURE_FIND_GROUP( "-group\0" )
737 IF_FEATURE_FIND_SIZE( "-size\0" )
738 IF_FEATURE_FIND_CONTEXT("-context\0")
Matheus Izvekovd0f601f2010-01-06 09:19:04 +0100739 IF_FEATURE_FIND_LINKS( "-links\0" )
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000740 ;
Denis Vlasenko56fce002007-04-04 23:41:35 +0000741
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000742 action*** appp;
Bernhard Reutner-Fischer10b79962007-02-04 16:09:04 +0000743 unsigned cur_group = 0;
744 unsigned cur_action = 0;
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000745 IF_FEATURE_FIND_NOT( bool invert_flag = 0; )
Denis Vlasenko56fce002007-04-04 23:41:35 +0000746
Denis Vlasenko0f3a5802008-03-20 13:13:09 +0000747 /* This is the only place in busybox where we use nested function.
748 * So far more standard alternatives were bigger. */
749 /* Suppress a warning "func without a prototype" */
750 auto action* alloc_action(int sizeof_struct, action_fp f);
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000751 action* alloc_action(int sizeof_struct, action_fp f)
752 {
753 action *ap;
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000754 appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(*appp));
755 appp[cur_group][cur_action++] = ap = xmalloc(sizeof_struct);
756 appp[cur_group][cur_action] = NULL;
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000757 ap->f = f;
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000758 IF_FEATURE_FIND_NOT( ap->invert = invert_flag; )
759 IF_FEATURE_FIND_NOT( invert_flag = 0; )
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000760 return ap;
761 }
Denis Vlasenko56fce002007-04-04 23:41:35 +0000762
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000763#define ALLOC_ACTION(name) (action_##name*)alloc_action(sizeof(action_##name), (action_fp) func_##name)
Eric Andersen17d49ef1999-10-06 20:25:32 +0000764
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000765 appp = xzalloc(2 * sizeof(appp[0])); /* appp[0],[1] == NULL */
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000766
Bernhard Reutner-Fischer557b4582007-03-29 13:55:17 +0000767/* Actions have side effects and return a true or false value
768 * We implement: -print, -print0, -exec
769 *
770 * The rest are tests.
771 *
772 * Tests and actions are grouped by operators
773 * ( expr ) Force precedence
774 * ! expr True if expr is false
775 * -not expr Same as ! expr
776 * expr1 [-a[nd]] expr2 And; expr2 is not evaluated if expr1 is false
777 * expr1 -o[r] expr2 Or; expr2 is not evaluated if expr1 is true
778 * expr1 , expr2 List; both expr1 and expr2 are always evaluated
779 * We implement: (), -a, -o
780 */
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000781 while (*argv) {
Denis Vlasenko434ad542007-01-27 13:45:17 +0000782 const char *arg = argv[0];
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000783 int parm = index_in_strings(params, arg);
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000784 const char *arg1 = argv[1];
785
786 if (parm >= PARM_name) {
787 /* All options starting from -name require argument */
788 if (!arg1)
789 bb_error_msg_and_die(bb_msg_requires_arg, arg);
790 argv++;
791 }
792
793 /* We can use big switch() here, but on i386
794 * it doesn't give smaller code. Other arches? */
795
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000796 /* --- Operators --- */
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000797 if (parm == PARM_a IF_DESKTOP(|| parm == PARM_and)) {
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000798 /* no further special handling required */
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000799 }
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000800 else if (parm == PARM_o IF_DESKTOP(|| parm == PARM_or)) {
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000801 /* start new OR group */
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000802 cur_group++;
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000803 appp = xrealloc(appp, (cur_group+2) * sizeof(*appp));
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000804 /*appp[cur_group] = NULL; - already NULL */
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000805 appp[cur_group+1] = NULL;
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000806 cur_action = 0;
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000807 }
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000808#if ENABLE_FEATURE_FIND_NOT
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000809 else if (parm == PARM_char_not IF_DESKTOP(|| parm == PARM_not)) {
Denis Vlasenkob2922642007-02-06 17:38:29 +0000810 /* also handles "find ! ! -name 'foo*'" */
811 invert_flag ^= 1;
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000812 }
813#endif
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000814
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000815 /* --- Tests and actions --- */
Denis Vlasenko56fce002007-04-04 23:41:35 +0000816 else if (parm == PARM_print) {
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200817 G.need_print = 0;
Denis Vlasenkocf787cf2007-02-04 17:11:25 +0000818 /* GNU find ignores '!' here: "find ! -print" */
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000819 IF_FEATURE_FIND_NOT( invert_flag = 0; )
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000820 (void) ALLOC_ACTION(print);
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000821 }
822#if ENABLE_FEATURE_FIND_PRINT0
Denis Vlasenko56fce002007-04-04 23:41:35 +0000823 else if (parm == PARM_print0) {
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200824 G.need_print = 0;
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000825 IF_FEATURE_FIND_NOT( invert_flag = 0; )
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000826 (void) ALLOC_ACTION(print0);
827 }
Paul Foxd7384292006-05-12 14:47:20 +0000828#endif
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000829#if ENABLE_FEATURE_FIND_DEPTH
830 else if (parm == PARM_depth) {
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200831 G.recurse_flags |= ACTION_DEPTHFIRST;
Denis Vlasenkob9411292007-06-15 23:43:11 +0000832 }
833#endif
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000834#if ENABLE_FEATURE_FIND_PRUNE
835 else if (parm == PARM_prune) {
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000836 IF_FEATURE_FIND_NOT( invert_flag = 0; )
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000837 (void) ALLOC_ACTION(prune);
Denis Vlasenkob9411292007-06-15 23:43:11 +0000838 }
839#endif
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000840#if ENABLE_FEATURE_FIND_DELETE
841 else if (parm == PARM_delete) {
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200842 G.need_print = 0;
843 G.recurse_flags |= ACTION_DEPTHFIRST;
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000844 (void) ALLOC_ACTION(delete);
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000845 }
Rob Landleycee605c2005-10-06 16:39:17 +0000846#endif
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000847#if ENABLE_FEATURE_FIND_EXEC
Denis Vlasenko56fce002007-04-04 23:41:35 +0000848 else if (parm == PARM_exec) {
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000849 int i;
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000850 action_exec *ap;
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +0200851 G.need_print = 0;
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000852 IF_FEATURE_FIND_NOT( invert_flag = 0; )
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000853 ap = ALLOC_ACTION(exec);
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000854 ap->exec_argv = ++argv; /* first arg after -exec */
855 ap->exec_argc = 0;
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000856 while (1) {
Bernhard Reutner-Fischer2e73d842010-02-25 13:22:37 +0100857 if (!*argv) /* did not see ';' or '+' until end */
858 bb_error_msg_and_die(bb_msg_requires_arg, "-exec");
Denis Vlasenko9ac9e552006-12-23 15:58:11 +0000859 if (LONE_CHAR(argv[0], ';'))
Rob Landley5d3a0e82005-10-04 03:34:39 +0000860 break;
Bernhard Reutner-Fischer2e73d842010-02-25 13:22:37 +0100861 //TODO: implement {} + (like xargs)
862 // See:
863 // find findutils/ -exec echo ">"{}"<" \;
864 // find findutils/ -exec echo ">"{}"<" +
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000865 argv++;
866 ap->exec_argc++;
Rob Landley5d3a0e82005-10-04 03:34:39 +0000867 }
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000868 if (ap->exec_argc == 0)
Denis Vlasenkodf0553b2006-10-29 00:21:47 +0000869 bb_error_msg_and_die(bb_msg_requires_arg, arg);
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000870 ap->subst_count = xmalloc(ap->exec_argc * sizeof(int));
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000871 i = ap->exec_argc;
872 while (i--)
873 ap->subst_count[i] = count_subst(ap->exec_argv[i]);
874 }
875#endif
Denis Vlasenko56fce002007-04-04 23:41:35 +0000876#if ENABLE_FEATURE_FIND_PAREN
877 else if (parm == PARM_char_brace) {
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000878 action_paren *ap;
879 char **endarg;
Bernhard Reutner-Fischer10b79962007-02-04 16:09:04 +0000880 unsigned nested = 1;
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000881
882 endarg = argv;
883 while (1) {
884 if (!*++endarg)
885 bb_error_msg_and_die("unpaired '('");
Denis Vlasenko9ac9e552006-12-23 15:58:11 +0000886 if (LONE_CHAR(*endarg, '('))
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000887 nested++;
Denis Vlasenko9ac9e552006-12-23 15:58:11 +0000888 else if (LONE_CHAR(*endarg, ')') && !--nested) {
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000889 *endarg = NULL;
890 break;
891 }
892 }
893 ap = ALLOC_ACTION(paren);
894 ap->subexpr = parse_params(argv + 1);
Denis Vlasenkoab2aea42007-01-29 22:51:58 +0000895 *endarg = (char*) ")"; /* restore NULLed parameter */
Denis Vlasenko6191a7a2006-10-30 02:10:47 +0000896 argv = endarg;
Denis Vlasenko5d499e12006-10-29 19:07:01 +0000897 }
Denis Vlasenko56fce002007-04-04 23:41:35 +0000898#endif
Denis Vlasenko75aa6152007-12-09 10:07:39 +0000899 else if (parm == PARM_name || parm == PARM_iname) {
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000900 action_name *ap;
901 ap = ALLOC_ACTION(name);
902 ap->pattern = arg1;
Denis Vlasenko75aa6152007-12-09 10:07:39 +0000903 ap->iname = (parm == PARM_iname);
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000904 }
905#if ENABLE_FEATURE_FIND_PATH
906 else if (parm == PARM_path) {
907 action_path *ap;
908 ap = ALLOC_ACTION(path);
909 ap->pattern = arg1;
910 }
911#endif
912#if ENABLE_FEATURE_FIND_REGEX
913 else if (parm == PARM_regex) {
914 action_regex *ap;
915 ap = ALLOC_ACTION(regex);
916 xregcomp(&ap->compiled_pattern, arg1, 0 /*cflags*/);
917 }
918#endif
919#if ENABLE_FEATURE_FIND_TYPE
920 else if (parm == PARM_type) {
921 action_type *ap;
922 ap = ALLOC_ACTION(type);
923 ap->type_mask = find_type(arg1);
924 }
925#endif
926#if ENABLE_FEATURE_FIND_PERM
927/* -perm mode File's permission bits are exactly mode (octal or symbolic).
928 * Symbolic modes use mode 0 as a point of departure.
929 * -perm -mode All of the permission bits mode are set for the file.
930 * -perm +mode Any of the permission bits mode are set for the file.
931 */
932 else if (parm == PARM_perm) {
933 action_perm *ap;
934 ap = ALLOC_ACTION(perm);
935 ap->perm_char = arg1[0];
936 arg1 = plus_minus_num(arg1);
937 ap->perm_mask = 0;
938 if (!bb_parse_mode(arg1, &ap->perm_mask))
Denys Vlasenko651a2692010-03-23 16:25:17 +0100939 bb_error_msg_and_die("invalid mode '%s'", arg1);
Denis Vlasenkoa19faf82007-06-19 22:22:57 +0000940 }
941#endif
942#if ENABLE_FEATURE_FIND_MTIME
943 else if (parm == PARM_mtime) {
944 action_mtime *ap;
945 ap = ALLOC_ACTION(mtime);
946 ap->mtime_char = arg1[0];
947 ap->mtime_days = xatoul(plus_minus_num(arg1));
948 }
949#endif
950#if ENABLE_FEATURE_FIND_MMIN
951 else if (parm == PARM_mmin) {
952 action_mmin *ap;
953 ap = ALLOC_ACTION(mmin);
954 ap->mmin_char = arg1[0];
955 ap->mmin_mins = xatoul(plus_minus_num(arg1));
956 }
957#endif
958#if ENABLE_FEATURE_FIND_NEWER
959 else if (parm == PARM_newer) {
960 struct stat stat_newer;
961 action_newer *ap;
962 ap = ALLOC_ACTION(newer);
963 xstat(arg1, &stat_newer);
964 ap->newer_mtime = stat_newer.st_mtime;
965 }
966#endif
967#if ENABLE_FEATURE_FIND_INUM
968 else if (parm == PARM_inum) {
969 action_inum *ap;
970 ap = ALLOC_ACTION(inum);
971 ap->inode_num = xatoul(arg1);
972 }
973#endif
974#if ENABLE_FEATURE_FIND_USER
975 else if (parm == PARM_user) {
976 action_user *ap;
977 ap = ALLOC_ACTION(user);
978 ap->uid = bb_strtou(arg1, NULL, 10);
979 if (errno)
980 ap->uid = xuname2uid(arg1);
981 }
982#endif
983#if ENABLE_FEATURE_FIND_GROUP
984 else if (parm == PARM_group) {
985 action_group *ap;
986 ap = ALLOC_ACTION(group);
987 ap->gid = bb_strtou(arg1, NULL, 10);
988 if (errno)
989 ap->gid = xgroup2gid(arg1);
990 }
991#endif
Denis Vlasenkob9411292007-06-15 23:43:11 +0000992#if ENABLE_FEATURE_FIND_SIZE
993 else if (parm == PARM_size) {
Denis Vlasenko53a0e972007-06-16 00:30:52 +0000994/* -size n[bckw]: file uses n units of space
995 * b (default): units are 512-byte blocks
996 * c: 1 byte
997 * k: kilobytes
998 * w: 2-byte words
999 */
1000#if ENABLE_LFS
1001#define XATOU_SFX xatoull_sfx
1002#else
1003#define XATOU_SFX xatoul_sfx
1004#endif
1005 static const struct suffix_mult find_suffixes[] = {
Denis Vlasenko99fcc622007-07-01 17:29:44 +00001006 { "c", 1 },
1007 { "w", 2 },
Denis Vlasenkof8689632007-07-27 15:06:25 +00001008 { "", 512 },
Denis Vlasenko99fcc622007-07-01 17:29:44 +00001009 { "b", 512 },
1010 { "k", 1024 },
Denys Vlasenko043b1e52009-09-06 12:47:55 +02001011 { "", 0 }
Denis Vlasenko53a0e972007-06-16 00:30:52 +00001012 };
Denis Vlasenkob9411292007-06-15 23:43:11 +00001013 action_size *ap;
Denis Vlasenkob9411292007-06-15 23:43:11 +00001014 ap = ALLOC_ACTION(size);
Denis Vlasenko53a0e972007-06-16 00:30:52 +00001015 ap->size_char = arg1[0];
1016 ap->size = XATOU_SFX(plus_minus_num(arg1), find_suffixes);
Denis Vlasenkob9411292007-06-15 23:43:11 +00001017 }
1018#endif
Denis Vlasenkoa19faf82007-06-19 22:22:57 +00001019#if ENABLE_FEATURE_FIND_CONTEXT
1020 else if (parm == PARM_context) {
1021 action_context *ap;
1022 ap = ALLOC_ACTION(context);
1023 ap->context = NULL;
Denis Vlasenko838daca2007-08-16 10:41:24 +00001024 /* SELinux headers erroneously declare non-const parameter */
1025 if (selinux_raw_to_trans_context((char*)arg1, &ap->context))
Denis Vlasenko0c97c9d2007-10-01 11:58:38 +00001026 bb_simple_perror_msg(arg1);
Denis Vlasenko62f04792007-04-13 10:00:12 +00001027 }
1028#endif
Matheus Izvekovd0f601f2010-01-06 09:19:04 +01001029#if ENABLE_FEATURE_FIND_LINKS
1030 else if (parm == PARM_links) {
1031 action_links *ap;
1032 ap = ALLOC_ACTION(links);
1033 ap->links_char = arg1[0];
1034 ap->links_count = xatoul(plus_minus_num(arg1));
1035 }
1036#endif
Denis Vlasenkob9411292007-06-15 23:43:11 +00001037 else {
1038 bb_error_msg("unrecognized: %s", arg);
Manuel Novoa III cad53642003-03-19 09:13:01 +00001039 bb_show_usage();
Denis Vlasenkob9411292007-06-15 23:43:11 +00001040 }
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001041 argv++;
Erik Andersene49d5ec2000-02-08 19:58:47 +00001042 }
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001043 return appp;
1044#undef ALLOC_ACTION
1045}
1046
1047
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +00001048int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denys Vlasenko2ec91ae2010-01-04 14:15:38 +01001049int find_main(int argc UNUSED_PARAM, char **argv)
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001050{
Denis Vlasenko6ca409e2007-08-12 20:58:27 +00001051 static const char options[] ALIGN1 =
Denis Vlasenko990d0f62007-07-24 15:54:42 +00001052 "-follow\0"
Denis Vlasenko5e34ff22009-04-21 11:09:40 +00001053IF_FEATURE_FIND_XDEV( "-xdev\0" )
1054IF_FEATURE_FIND_MAXDEPTH("-mindepth\0""-maxdepth\0")
Denis Vlasenko990d0f62007-07-24 15:54:42 +00001055 ;
Denis Vlasenkob9411292007-06-15 23:43:11 +00001056 enum {
Denis Vlasenko990d0f62007-07-24 15:54:42 +00001057 OPT_FOLLOW,
Denis Vlasenko5e34ff22009-04-21 11:09:40 +00001058IF_FEATURE_FIND_XDEV( OPT_XDEV ,)
1059IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,)
Denis Vlasenkob9411292007-06-15 23:43:11 +00001060 };
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001061
Denis Vlasenko7d6c9292007-04-05 00:35:43 +00001062 char *arg;
1063 char **argp;
1064 int i, firstopt, status = EXIT_SUCCESS;
Denis Vlasenkob9411292007-06-15 23:43:11 +00001065#if ENABLE_FEATURE_FIND_MAXDEPTH
Denis Vlasenko83518d12009-03-20 22:17:13 +00001066 int minmaxdepth[2] = { 0, INT_MAX };
1067#else
1068#define minmaxdepth NULL
Denis Vlasenkob9411292007-06-15 23:43:11 +00001069#endif
Denis Vlasenko7d6c9292007-04-05 00:35:43 +00001070
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +02001071 INIT_G();
1072
Denys Vlasenko2ec91ae2010-01-04 14:15:38 +01001073 for (firstopt = 1; argv[firstopt]; firstopt++) {
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001074 if (argv[firstopt][0] == '-')
1075 break;
Denis Vlasenkocf787cf2007-02-04 17:11:25 +00001076 if (ENABLE_FEATURE_FIND_NOT && LONE_CHAR(argv[firstopt], '!'))
1077 break;
Denis Vlasenko56fce002007-04-04 23:41:35 +00001078#if ENABLE_FEATURE_FIND_PAREN
Denis Vlasenko9ac9e552006-12-23 15:58:11 +00001079 if (LONE_CHAR(argv[firstopt], '('))
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001080 break;
1081#endif
1082 }
1083 if (firstopt == 1) {
Denis Vlasenkoab2aea42007-01-29 22:51:58 +00001084 argv[0] = (char*)".";
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001085 argv--;
1086 firstopt++;
1087 }
1088
Bernhard Reutner-Fischer32773ac2007-03-29 13:54:17 +00001089/* All options always return true. They always take effect
1090 * rather than being processed only when their place in the
1091 * expression is reached.
Denis Vlasenkob9411292007-06-15 23:43:11 +00001092 * We implement: -follow, -xdev, -maxdepth
Bernhard Reutner-Fischer32773ac2007-03-29 13:54:17 +00001093 */
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001094 /* Process options, and replace then with -a */
Denis Vlasenko92258542006-11-01 10:25:35 +00001095 /* (-a will be ignored by recursive parser later) */
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001096 argp = &argv[firstopt];
Denis Vlasenko92258542006-11-01 10:25:35 +00001097 while ((arg = argp[0])) {
Denis Vlasenko990d0f62007-07-24 15:54:42 +00001098 int opt = index_in_strings(options, arg);
Denis Vlasenkob9411292007-06-15 23:43:11 +00001099 if (opt == OPT_FOLLOW) {
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +02001100 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
Denis Vlasenkoab2aea42007-01-29 22:51:58 +00001101 argp[0] = (char*)"-a";
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001102 }
1103#if ENABLE_FEATURE_FIND_XDEV
Denis Vlasenkob9411292007-06-15 23:43:11 +00001104 if (opt == OPT_XDEV) {
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001105 struct stat stbuf;
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +02001106 if (!G.xdev_count) {
1107 G.xdev_count = firstopt - 1;
Denys Vlasenkoce9b97f2010-01-10 02:33:02 +01001108 G.xdev_dev = xzalloc(G.xdev_count * sizeof(G.xdev_dev[0]));
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001109 for (i = 1; i < firstopt; i++) {
1110 /* not xstat(): shouldn't bomb out on
1111 * "find not_exist exist -xdev" */
Denys Vlasenkoce9b97f2010-01-10 02:33:02 +01001112 if (stat(argv[i], &stbuf) == 0)
1113 G.xdev_dev[i-1] = stbuf.st_dev;
1114 /* else G.xdev_dev[i-1] stays 0 and
1115 * won't match any real device dev_t */
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001116 }
1117 }
Denis Vlasenkoab2aea42007-01-29 22:51:58 +00001118 argp[0] = (char*)"-a";
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001119 }
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001120#endif
Denis Vlasenkob9411292007-06-15 23:43:11 +00001121#if ENABLE_FEATURE_FIND_MAXDEPTH
Denis Vlasenko83518d12009-03-20 22:17:13 +00001122 if (opt == OPT_MINDEPTH || opt == OPT_MINDEPTH + 1) {
Denis Vlasenkob9411292007-06-15 23:43:11 +00001123 if (!argp[1])
1124 bb_show_usage();
Denis Vlasenko83518d12009-03-20 22:17:13 +00001125 minmaxdepth[opt - OPT_MINDEPTH] = xatoi_u(argp[1]);
Denis Vlasenkob9411292007-06-15 23:43:11 +00001126 argp[0] = (char*)"-a";
1127 argp[1] = (char*)"-a";
1128 argp++;
1129 }
1130#endif
Denis Vlasenkoc9d34da2007-01-03 03:15:58 +00001131 argp++;
Denis Vlasenko666da5e2006-12-26 18:17:42 +00001132 }
Denis Vlasenko6191a7a2006-10-30 02:10:47 +00001133
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +02001134 G.actions = parse_params(&argv[firstopt]);
Denis Vlasenko5d499e12006-10-29 19:07:01 +00001135
Denis Vlasenkoe2fb7192006-10-29 19:03:56 +00001136 for (i = 1; i < firstopt; i++) {
1137 if (!recursive_action(argv[i],
Denys Vlasenko8f7a6d22009-09-29 11:07:04 +02001138 G.recurse_flags,/* flags */
Bernhard Reutner-Fischer3e816c12007-03-29 10:30:50 +00001139 fileAction, /* file action */
1140 fileAction, /* dir action */
Denis Vlasenkob9411292007-06-15 23:43:11 +00001141#if ENABLE_FEATURE_FIND_MAXDEPTH
Denis Vlasenko83518d12009-03-20 22:17:13 +00001142 minmaxdepth, /* user data */
Denis Vlasenkob9411292007-06-15 23:43:11 +00001143#else
Bernhard Reutner-Fischer3e816c12007-03-29 10:30:50 +00001144 NULL, /* user data */
Denis Vlasenkob9411292007-06-15 23:43:11 +00001145#endif
Bernhard Reutner-Fischer3e816c12007-03-29 10:30:50 +00001146 0)) /* depth */
Denis Vlasenkoe2fb7192006-10-29 19:03:56 +00001147 status = EXIT_FAILURE;
1148 }
Matt Kraai096370d2001-02-07 03:52:38 +00001149 return status;
Eric Andersen17d49ef1999-10-06 20:25:32 +00001150}