Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini find implementation for busybox |
| 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 6 | * |
Matt Kraai | 096370d | 2001-02-07 03:52:38 +0000 | [diff] [blame] | 7 | * Reworked by David Douthitt <n9ubh@callsign.net> and |
| 8 | * Matt Kraai <kraai@alumni.carnegiemellon.edu>. |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 9 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 10 | * Licensed under GPLv2, see file LICENSE in this source tree. |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 13 | /* 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 Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 26 | * # find file.txt -exec 'echo' '{} {}' ';' -print -exec pwd ';' |
| 27 | * file.txt file.txt |
| 28 | * file.txt |
| 29 | * /tmp |
Denis Vlasenko | e2fb719 | 2006-10-29 19:03:56 +0000 | [diff] [blame] | 30 | * # find -name '*.c' -o -name '*.h' |
| 31 | * [shows files, *.c and *.h intermixed] |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 32 | * # 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 Vlasenko | a3b4fed | 2006-10-31 03:20:13 +0000 | [diff] [blame] | 38 | * |
| 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 Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 46 | */ |
| 47 | |
Denis Vlasenko | 53a0e97 | 2007-06-16 00:30:52 +0000 | [diff] [blame] | 48 | /* 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 Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 56 | //config:config FIND |
| 57 | //config: bool "find" |
Denys Vlasenko | 2f32bf8 | 2010-06-06 04:14:28 +0200 | [diff] [blame] | 58 | //config: default y |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 59 | //config: help |
| 60 | //config: find is used to search your system to find specified files. |
| 61 | //config: |
| 62 | //config:config FEATURE_FIND_PRINT0 |
| 63 | //config: bool "Enable -print0: NUL-terminated output" |
| 64 | //config: default y |
| 65 | //config: depends on FIND |
| 66 | //config: help |
| 67 | //config: Causes output names to be separated by a NUL character |
| 68 | //config: rather than a newline. This allows names that contain |
| 69 | //config: newlines and other whitespace to be more easily |
| 70 | //config: interpreted by other programs. |
| 71 | //config: |
| 72 | //config:config FEATURE_FIND_MTIME |
| 73 | //config: bool "Enable -mtime: modified time matching" |
| 74 | //config: default y |
| 75 | //config: depends on FIND |
| 76 | //config: help |
| 77 | //config: Allow searching based on the modification time of |
| 78 | //config: files, in days. |
| 79 | //config: |
| 80 | //config:config FEATURE_FIND_MMIN |
| 81 | //config: bool "Enable -mmin: modified time matching by minutes" |
| 82 | //config: default y |
| 83 | //config: depends on FIND |
| 84 | //config: help |
| 85 | //config: Allow searching based on the modification time of |
| 86 | //config: files, in minutes. |
| 87 | //config: |
| 88 | //config:config FEATURE_FIND_PERM |
| 89 | //config: bool "Enable -perm: permissions matching" |
| 90 | //config: default y |
| 91 | //config: depends on FIND |
| 92 | //config: help |
| 93 | //config: Enable searching based on file permissions. |
| 94 | //config: |
| 95 | //config:config FEATURE_FIND_TYPE |
| 96 | //config: bool "Enable -type: file type matching (file/dir/link/...)" |
| 97 | //config: default y |
| 98 | //config: depends on FIND |
| 99 | //config: help |
| 100 | //config: Enable searching based on file type (file, |
| 101 | //config: directory, socket, device, etc.). |
| 102 | //config: |
| 103 | //config:config FEATURE_FIND_XDEV |
| 104 | //config: bool "Enable -xdev: 'stay in filesystem'" |
| 105 | //config: default y |
| 106 | //config: depends on FIND |
| 107 | //config: help |
| 108 | //config: This option allows find to restrict searches to a single filesystem. |
| 109 | //config: |
| 110 | //config:config FEATURE_FIND_MAXDEPTH |
Denys Vlasenko | cef85c2 | 2011-02-12 16:35:24 +0100 | [diff] [blame] | 111 | //config: bool "Enable -mindepth N and -maxdepth N" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 112 | //config: default y |
| 113 | //config: depends on FIND |
| 114 | //config: help |
Denys Vlasenko | cef85c2 | 2011-02-12 16:35:24 +0100 | [diff] [blame] | 115 | //config: This option enables -mindepth N and -maxdepth N option. |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 116 | //config: |
| 117 | //config:config FEATURE_FIND_NEWER |
| 118 | //config: bool "Enable -newer: compare file modification times" |
| 119 | //config: default y |
| 120 | //config: depends on FIND |
| 121 | //config: help |
| 122 | //config: Support the 'find -newer' option for finding any files which have |
Denys Vlasenko | cef85c2 | 2011-02-12 16:35:24 +0100 | [diff] [blame] | 123 | //config: modification time that is more recent than the specified FILE. |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 124 | //config: |
| 125 | //config:config FEATURE_FIND_INUM |
| 126 | //config: bool "Enable -inum: inode number matching" |
| 127 | //config: default y |
| 128 | //config: depends on FIND |
| 129 | //config: help |
| 130 | //config: Support the 'find -inum' option for searching by inode number. |
| 131 | //config: |
| 132 | //config:config FEATURE_FIND_EXEC |
| 133 | //config: bool "Enable -exec: execute commands" |
| 134 | //config: default y |
| 135 | //config: depends on FIND |
| 136 | //config: help |
| 137 | //config: Support the 'find -exec' option for executing commands based upon |
| 138 | //config: the files matched. |
| 139 | //config: |
| 140 | //config:config FEATURE_FIND_USER |
| 141 | //config: bool "Enable -user: username/uid matching" |
| 142 | //config: default y |
| 143 | //config: depends on FIND |
| 144 | //config: help |
| 145 | //config: Support the 'find -user' option for searching by username or uid. |
| 146 | //config: |
| 147 | //config:config FEATURE_FIND_GROUP |
| 148 | //config: bool "Enable -group: group/gid matching" |
| 149 | //config: default y |
| 150 | //config: depends on FIND |
| 151 | //config: help |
| 152 | //config: Support the 'find -group' option for searching by group name or gid. |
| 153 | //config: |
| 154 | //config:config FEATURE_FIND_NOT |
| 155 | //config: bool "Enable the 'not' (!) operator" |
| 156 | //config: default y |
| 157 | //config: depends on FIND |
| 158 | //config: help |
| 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'. |
| 162 | //config: |
| 163 | //config:config FEATURE_FIND_DEPTH |
| 164 | //config: bool "Enable -depth" |
| 165 | //config: default y |
| 166 | //config: depends on FIND |
| 167 | //config: help |
| 168 | //config: Process each directory's contents before the directory itself. |
| 169 | //config: |
| 170 | //config:config FEATURE_FIND_PAREN |
| 171 | //config: bool "Enable parens in options" |
| 172 | //config: default y |
| 173 | //config: depends on FIND |
| 174 | //config: help |
| 175 | //config: Enable usage of parens '(' to specify logical order of arguments. |
| 176 | //config: |
| 177 | //config:config FEATURE_FIND_SIZE |
| 178 | //config: bool "Enable -size: file size matching" |
| 179 | //config: default y |
| 180 | //config: depends on FIND |
| 181 | //config: help |
| 182 | //config: Support the 'find -size' option for searching by file size. |
| 183 | //config: |
| 184 | //config:config FEATURE_FIND_PRUNE |
| 185 | //config: bool "Enable -prune: exclude subdirectories" |
| 186 | //config: default y |
| 187 | //config: depends on FIND |
| 188 | //config: help |
| 189 | //config: If the file is a directory, dont descend into it. Useful for |
| 190 | //config: exclusion .svn and CVS directories. |
| 191 | //config: |
| 192 | //config:config FEATURE_FIND_DELETE |
| 193 | //config: bool "Enable -delete: delete files/dirs" |
Denys Vlasenko | 2f32bf8 | 2010-06-06 04:14:28 +0200 | [diff] [blame] | 194 | //config: default y |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 195 | //config: depends on FIND && FEATURE_FIND_DEPTH |
| 196 | //config: help |
| 197 | //config: Support the 'find -delete' option for deleting files and directories. |
| 198 | //config: WARNING: This option can do much harm if used wrong. Busybox will not |
| 199 | //config: try to protect the user from doing stupid things. Use with care. |
| 200 | //config: |
| 201 | //config:config FEATURE_FIND_PATH |
| 202 | //config: bool "Enable -path: match pathname with shell pattern" |
| 203 | //config: default y |
| 204 | //config: depends on FIND |
| 205 | //config: help |
| 206 | //config: The -path option matches whole pathname instead of just filename. |
| 207 | //config: |
| 208 | //config:config FEATURE_FIND_REGEX |
| 209 | //config: bool "Enable -regex: match pathname with regex" |
| 210 | //config: default y |
| 211 | //config: depends on FIND |
| 212 | //config: help |
| 213 | //config: The -regex option matches whole pathname against regular expression. |
| 214 | //config: |
| 215 | //config:config FEATURE_FIND_CONTEXT |
| 216 | //config: bool "Enable -context: security context matching" |
| 217 | //config: default n |
| 218 | //config: depends on FIND && SELINUX |
| 219 | //config: help |
| 220 | //config: Support the 'find -context' option for matching security context. |
| 221 | //config: |
| 222 | //config:config FEATURE_FIND_LINKS |
| 223 | //config: bool "Enable -links: link count matching" |
Denys Vlasenko | 2f32bf8 | 2010-06-06 04:14:28 +0200 | [diff] [blame] | 224 | //config: default y |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 225 | //config: depends on FIND |
| 226 | //config: help |
| 227 | //config: Support the 'find -links' option for matching number of links. |
| 228 | |
Denys Vlasenko | 805f245 | 2011-02-12 20:26:14 +0100 | [diff] [blame] | 229 | //applet:IF_FIND(APPLET_NOEXEC(find, find, BB_DIR_USR_BIN, BB_SUID_DROP, find)) |
| 230 | |
| 231 | //kbuild:lib-$(CONFIG_FIND) += find.o |
| 232 | |
| 233 | //usage:#define find_trivial_usage |
Denys Vlasenko | 6782f48 | 2013-05-14 17:20:35 +0200 | [diff] [blame] | 234 | //usage: "[-HL] [PATH]... [OPTIONS] [ACTIONS]" |
Denys Vlasenko | 805f245 | 2011-02-12 20:26:14 +0100 | [diff] [blame] | 235 | //usage:#define find_full_usage "\n\n" |
| 236 | //usage: "Search for files and perform actions on them.\n" |
| 237 | //usage: "First failed action stops processing of current file.\n" |
| 238 | //usage: "Defaults: PATH is current directory, action is '-print'\n" |
Denys Vlasenko | 6782f48 | 2013-05-14 17:20:35 +0200 | [diff] [blame] | 239 | //usage: "\n -L,-follow Follow symlinks" |
| 240 | //usage: "\n -H ...on command line only" |
Denys Vlasenko | 805f245 | 2011-02-12 20:26:14 +0100 | [diff] [blame] | 241 | //usage: IF_FEATURE_FIND_XDEV( |
| 242 | //usage: "\n -xdev Don't descend directories on other filesystems" |
| 243 | //usage: ) |
| 244 | //usage: IF_FEATURE_FIND_MAXDEPTH( |
| 245 | //usage: "\n -maxdepth N Descend at most N levels. -maxdepth 0 applies" |
| 246 | //usage: "\n actions to command line arguments only" |
| 247 | //usage: "\n -mindepth N Don't act on first N levels" |
| 248 | //usage: ) |
| 249 | //usage: IF_FEATURE_FIND_DEPTH( |
| 250 | //usage: "\n -depth Act on directory *after* traversing it" |
| 251 | //usage: ) |
| 252 | //usage: "\n" |
| 253 | //usage: "\nActions:" |
| 254 | //usage: IF_FEATURE_FIND_PAREN( |
| 255 | //usage: "\n ( ACTIONS ) Group actions for -o / -a" |
| 256 | //usage: ) |
| 257 | //usage: IF_FEATURE_FIND_NOT( |
| 258 | //usage: "\n ! ACT Invert ACT's success/failure" |
| 259 | //usage: ) |
| 260 | //usage: "\n ACT1 [-a] ACT2 If ACT1 fails, stop, else do ACT2" |
| 261 | //usage: "\n ACT1 -o ACT2 If ACT1 succeeds, stop, else do ACT2" |
| 262 | //usage: "\n Note: -a has higher priority than -o" |
| 263 | //usage: "\n -name PATTERN Match file name (w/o directory name) to PATTERN" |
| 264 | //usage: "\n -iname PATTERN Case insensitive -name" |
| 265 | //usage: IF_FEATURE_FIND_PATH( |
| 266 | //usage: "\n -path PATTERN Match path to PATTERN" |
Bogdan Harjoc | 7948ecb | 2011-05-22 03:50:21 +0200 | [diff] [blame] | 267 | //usage: "\n -ipath PATTERN Case insensitive -path" |
Denys Vlasenko | 805f245 | 2011-02-12 20:26:14 +0100 | [diff] [blame] | 268 | //usage: ) |
| 269 | //usage: IF_FEATURE_FIND_REGEX( |
| 270 | //usage: "\n -regex PATTERN Match path to regex PATTERN" |
| 271 | //usage: ) |
| 272 | //usage: IF_FEATURE_FIND_TYPE( |
| 273 | //usage: "\n -type X File type is X (one of: f,d,l,b,c,...)" |
| 274 | //usage: ) |
| 275 | //usage: IF_FEATURE_FIND_PERM( |
| 276 | //usage: "\n -perm MASK At least one mask bit (+MASK), all bits (-MASK)," |
Denys Vlasenko | e1a4209 | 2011-02-12 20:37:41 +0100 | [diff] [blame] | 277 | //usage: "\n or exactly MASK bits are set in file's mode" |
Denys Vlasenko | 805f245 | 2011-02-12 20:26:14 +0100 | [diff] [blame] | 278 | //usage: ) |
| 279 | //usage: IF_FEATURE_FIND_MTIME( |
Denys Vlasenko | e1a4209 | 2011-02-12 20:37:41 +0100 | [diff] [blame] | 280 | //usage: "\n -mtime DAYS mtime is greater than (+N), less than (-N)," |
| 281 | //usage: "\n or exactly N days in the past" |
Denys Vlasenko | 805f245 | 2011-02-12 20:26:14 +0100 | [diff] [blame] | 282 | //usage: ) |
| 283 | //usage: IF_FEATURE_FIND_MMIN( |
Denys Vlasenko | e1a4209 | 2011-02-12 20:37:41 +0100 | [diff] [blame] | 284 | //usage: "\n -mmin MINS mtime is greater than (+N), less than (-N)," |
| 285 | //usage: "\n or exactly N minutes in the past" |
Denys Vlasenko | 805f245 | 2011-02-12 20:26:14 +0100 | [diff] [blame] | 286 | //usage: ) |
| 287 | //usage: IF_FEATURE_FIND_NEWER( |
Denys Vlasenko | e1a4209 | 2011-02-12 20:37:41 +0100 | [diff] [blame] | 288 | //usage: "\n -newer FILE mtime is more recent than FILE's" |
Denys Vlasenko | 805f245 | 2011-02-12 20:26:14 +0100 | [diff] [blame] | 289 | //usage: ) |
| 290 | //usage: IF_FEATURE_FIND_INUM( |
| 291 | //usage: "\n -inum N File has inode number N" |
| 292 | //usage: ) |
| 293 | //usage: IF_FEATURE_FIND_USER( |
Denys Vlasenko | e1a4209 | 2011-02-12 20:37:41 +0100 | [diff] [blame] | 294 | //usage: "\n -user NAME/ID File is owned by given user" |
Denys Vlasenko | 805f245 | 2011-02-12 20:26:14 +0100 | [diff] [blame] | 295 | //usage: ) |
| 296 | //usage: IF_FEATURE_FIND_GROUP( |
Denys Vlasenko | e1a4209 | 2011-02-12 20:37:41 +0100 | [diff] [blame] | 297 | //usage: "\n -group NAME/ID File is owned by given group" |
Denys Vlasenko | 805f245 | 2011-02-12 20:26:14 +0100 | [diff] [blame] | 298 | //usage: ) |
| 299 | //usage: IF_FEATURE_FIND_SIZE( |
| 300 | //usage: "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))" |
| 301 | //usage: "\n +/-N: file size is bigger/smaller than N" |
| 302 | //usage: ) |
| 303 | //usage: IF_FEATURE_FIND_LINKS( |
| 304 | //usage: "\n -links N Number of links is greater than (+N), less than (-N)," |
| 305 | //usage: "\n or exactly N" |
| 306 | //usage: ) |
| 307 | //usage: IF_FEATURE_FIND_CONTEXT( |
| 308 | //usage: "\n -context CTX File has specified security context" |
| 309 | //usage: ) |
| 310 | //usage: IF_FEATURE_FIND_PRUNE( |
| 311 | //usage: "\n -prune If current file is directory, don't descend into it" |
| 312 | //usage: ) |
| 313 | //usage: "\nIf none of the following actions is specified, -print is assumed" |
| 314 | //usage: "\n -print Print file name" |
| 315 | //usage: IF_FEATURE_FIND_PRINT0( |
| 316 | //usage: "\n -print0 Print file name, NUL terminated" |
| 317 | //usage: ) |
| 318 | //usage: IF_FEATURE_FIND_EXEC( |
| 319 | //usage: "\n -exec CMD ARG ; Run CMD with all instances of {} replaced by" |
| 320 | //usage: "\n file name. Fails if CMD exits with nonzero" |
| 321 | //usage: ) |
| 322 | //usage: IF_FEATURE_FIND_DELETE( |
| 323 | //usage: "\n -delete Delete current file/directory. Turns on -depth option" |
| 324 | //usage: ) |
| 325 | //usage: |
| 326 | //usage:#define find_example_usage |
| 327 | //usage: "$ find / -name passwd\n" |
| 328 | //usage: "/etc/passwd\n" |
| 329 | |
Matt Kraai | 096370d | 2001-02-07 03:52:38 +0000 | [diff] [blame] | 330 | #include <fnmatch.h> |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 331 | #include "libbb.h" |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 332 | #if ENABLE_FEATURE_FIND_REGEX |
Denys Vlasenko | b24ef03 | 2011-05-23 00:40:54 +0200 | [diff] [blame] | 333 | # include "xregex.h" |
| 334 | #endif |
| 335 | /* GNUism: */ |
| 336 | #ifndef FNM_CASEFOLD |
| 337 | # define FNM_CASEFOLD 0 |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 338 | #endif |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 339 | |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 340 | #define dbg(...) ((void)0) |
| 341 | /* #define dbg(...) bb_error_msg(__VA_ARGS__) */ |
| 342 | |
Denis Vlasenko | 99912ca | 2007-04-10 15:43:37 +0000 | [diff] [blame] | 343 | /* This is a NOEXEC applet. Be very careful! */ |
| 344 | |
| 345 | |
Denys Vlasenko | 6c750f1 | 2009-09-27 01:51:47 +0200 | [diff] [blame] | 346 | typedef int (*action_fp)(const char *fileName, const struct stat *statbuf, void *) FAST_FUNC; |
Matt Kraai | 096370d | 2001-02-07 03:52:38 +0000 | [diff] [blame] | 347 | |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 348 | typedef struct { |
| 349 | action_fp f; |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 350 | #if ENABLE_FEATURE_FIND_NOT |
Bernhard Reutner-Fischer | 32773ac | 2007-03-29 13:54:17 +0000 | [diff] [blame] | 351 | bool invert; |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 352 | #endif |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 353 | } action; |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 354 | |
Denys Vlasenko | 606291b | 2009-09-23 23:15:43 +0200 | [diff] [blame] | 355 | #define ACTS(name, ...) typedef struct { action a; __VA_ARGS__ } action_##name; |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 356 | #define ACTF(name) \ |
| 357 | static int FAST_FUNC func_##name(const char *fileName UNUSED_PARAM, \ |
Denys Vlasenko | 6c750f1 | 2009-09-27 01:51:47 +0200 | [diff] [blame] | 358 | const struct stat *statbuf UNUSED_PARAM, \ |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 359 | action_##name* ap UNUSED_PARAM) |
| 360 | |
| 361 | ACTS(print) |
| 362 | ACTS(name, const char *pattern; bool iname;) |
Bogdan Harjoc | 7948ecb | 2011-05-22 03:50:21 +0200 | [diff] [blame] | 363 | IF_FEATURE_FIND_PATH( ACTS(path, const char *pattern; bool ipath;)) |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 364 | IF_FEATURE_FIND_REGEX( ACTS(regex, regex_t compiled_pattern;)) |
| 365 | IF_FEATURE_FIND_PRINT0( ACTS(print0)) |
| 366 | IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;)) |
| 367 | IF_FEATURE_FIND_PERM( ACTS(perm, char perm_char; mode_t perm_mask;)) |
| 368 | IF_FEATURE_FIND_MTIME( ACTS(mtime, char mtime_char; unsigned mtime_days;)) |
| 369 | IF_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; unsigned mmin_mins;)) |
| 370 | IF_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;)) |
| 371 | IF_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;)) |
| 372 | IF_FEATURE_FIND_USER( ACTS(user, uid_t uid;)) |
| 373 | IF_FEATURE_FIND_SIZE( ACTS(size, char size_char; off_t size;)) |
| 374 | IF_FEATURE_FIND_CONTEXT(ACTS(context, security_context_t context;)) |
| 375 | IF_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;)) |
| 376 | IF_FEATURE_FIND_PRUNE( ACTS(prune)) |
| 377 | IF_FEATURE_FIND_DELETE( ACTS(delete)) |
| 378 | IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;)) |
| 379 | IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;)) |
Matheus Izvekov | d0f601f | 2010-01-06 09:19:04 +0100 | [diff] [blame] | 380 | IF_FEATURE_FIND_LINKS( ACTS(links, char links_char; int links_count;)) |
Matt Kraai | 096370d | 2001-02-07 03:52:38 +0000 | [diff] [blame] | 381 | |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 382 | struct globals { |
| 383 | IF_FEATURE_FIND_XDEV(dev_t *xdev_dev;) |
| 384 | IF_FEATURE_FIND_XDEV(int xdev_count;) |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 385 | #if ENABLE_FEATURE_FIND_MAXDEPTH |
| 386 | int minmaxdepth[2]; |
| 387 | #endif |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 388 | action ***actions; |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 389 | smallint need_print; |
| 390 | smallint xdev_on; |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 391 | recurse_flags_t recurse_flags; |
Denys Vlasenko | 98a4c7c | 2010-02-04 15:00:15 +0100 | [diff] [blame] | 392 | } FIX_ALIASING; |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 393 | #define G (*(struct globals*)&bb_common_bufsiz1) |
| 394 | #define INIT_G() do { \ |
| 395 | struct G_sizecheck { \ |
| 396 | char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \ |
| 397 | }; \ |
Denys Vlasenko | 1b34d4f | 2009-09-30 02:39:57 +0200 | [diff] [blame] | 398 | /* we have to zero it out because of NOEXEC */ \ |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 399 | memset(&G, 0, sizeof(G)); \ |
| 400 | IF_FEATURE_FIND_MAXDEPTH(G.minmaxdepth[1] = INT_MAX;) \ |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 401 | G.need_print = 1; \ |
| 402 | G.recurse_flags = ACTION_RECURSE; \ |
| 403 | } while (0) |
Rob Landley | 5d3a0e8 | 2005-10-04 03:34:39 +0000 | [diff] [blame] | 404 | |
Denis Vlasenko | 666da5e | 2006-12-26 18:17:42 +0000 | [diff] [blame] | 405 | #if ENABLE_FEATURE_FIND_EXEC |
Denis Vlasenko | bbd695d | 2007-04-08 10:52:28 +0000 | [diff] [blame] | 406 | static unsigned count_subst(const char *str) |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 407 | { |
Denis Vlasenko | bbd695d | 2007-04-08 10:52:28 +0000 | [diff] [blame] | 408 | unsigned count = 0; |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 409 | while ((str = strstr(str, "{}")) != NULL) { |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 410 | count++; |
| 411 | str++; |
| 412 | } |
| 413 | return count; |
| 414 | } |
| 415 | |
| 416 | |
Denis Vlasenko | bbd695d | 2007-04-08 10:52:28 +0000 | [diff] [blame] | 417 | static char* subst(const char *src, unsigned count, const char* filename) |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 418 | { |
| 419 | char *buf, *dst, *end; |
Bernhard Reutner-Fischer | 32773ac | 2007-03-29 13:54:17 +0000 | [diff] [blame] | 420 | size_t flen = strlen(filename); |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 421 | /* we replace each '{}' with filename: growth by strlen-2 */ |
| 422 | buf = dst = xmalloc(strlen(src) + count*(flen-2) + 1); |
| 423 | while ((end = strstr(src, "{}"))) { |
| 424 | memcpy(dst, src, end - src); |
| 425 | dst += end - src; |
| 426 | src = end + 2; |
| 427 | memcpy(dst, filename, flen); |
| 428 | dst += flen; |
| 429 | } |
| 430 | strcpy(dst, src); |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 431 | return buf; |
| 432 | } |
Denis Vlasenko | 666da5e | 2006-12-26 18:17:42 +0000 | [diff] [blame] | 433 | #endif |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 434 | |
Denis Vlasenko | bbd695d | 2007-04-08 10:52:28 +0000 | [diff] [blame] | 435 | /* Return values of ACTFs ('action functions') are a bit mask: |
| 436 | * bit 1=1: prune (use SKIP constant for setting it) |
| 437 | * bit 0=1: matched successfully (TRUE) |
| 438 | */ |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 439 | |
Denys Vlasenko | 6c750f1 | 2009-09-27 01:51:47 +0200 | [diff] [blame] | 440 | static int exec_actions(action ***appp, const char *fileName, const struct stat *statbuf) |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 441 | { |
| 442 | int cur_group; |
| 443 | int cur_action; |
Denis Vlasenko | b04b435 | 2007-04-08 11:10:43 +0000 | [diff] [blame] | 444 | int rc = 0; |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 445 | action **app, *ap; |
| 446 | |
Denis Vlasenko | b04b435 | 2007-04-08 11:10:43 +0000 | [diff] [blame] | 447 | /* "action group" is a set of actions ANDed together. |
| 448 | * groups are ORed together. |
| 449 | * We simply evaluate each group until we find one in which all actions |
| 450 | * succeed. */ |
| 451 | |
| 452 | /* -prune is special: if it is encountered, then we won't |
| 453 | * descend into current directory. It doesn't matter whether |
| 454 | * action group (in which -prune sits) will succeed or not: |
| 455 | * find * -prune -name 'f*' -o -name 'm*' -- prunes every dir |
| 456 | * find * -name 'f*' -o -prune -name 'm*' -- prunes all dirs |
| 457 | * not starting with 'f' */ |
| 458 | |
| 459 | /* We invert TRUE bit (bit 0). Now 1 there means 'failure'. |
| 460 | * and bitwise OR in "rc |= TRUE ^ ap->f()" will: |
| 461 | * (1) make SKIP (-prune) bit stick; and (2) detect 'failure'. |
| 462 | * On return, bit is restored. */ |
| 463 | |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 464 | cur_group = -1; |
Matheus Izvekov | d0f601f | 2010-01-06 09:19:04 +0100 | [diff] [blame] | 465 | while ((app = appp[++cur_group]) != NULL) { |
Denis Vlasenko | b04b435 | 2007-04-08 11:10:43 +0000 | [diff] [blame] | 466 | rc &= ~TRUE; /* 'success' so far, clear TRUE bit */ |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 467 | cur_action = -1; |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 468 | while (1) { |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 469 | ap = app[++cur_action]; |
Denis Vlasenko | bbd695d | 2007-04-08 10:52:28 +0000 | [diff] [blame] | 470 | if (!ap) /* all actions in group were successful */ |
Denis Vlasenko | b04b435 | 2007-04-08 11:10:43 +0000 | [diff] [blame] | 471 | return rc ^ TRUE; /* restore TRUE bit */ |
Denis Vlasenko | bbd695d | 2007-04-08 10:52:28 +0000 | [diff] [blame] | 472 | rc |= TRUE ^ ap->f(fileName, statbuf, ap); |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 473 | #if ENABLE_FEATURE_FIND_NOT |
Denis Vlasenko | bbd695d | 2007-04-08 10:52:28 +0000 | [diff] [blame] | 474 | if (ap->invert) rc ^= TRUE; |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 475 | #endif |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 476 | dbg("grp %d action %d rc:0x%x", cur_group, cur_action, rc); |
Denis Vlasenko | bbd695d | 2007-04-08 10:52:28 +0000 | [diff] [blame] | 477 | if (rc & TRUE) /* current group failed, try next */ |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 478 | break; |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 479 | } |
| 480 | } |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 481 | dbg("returning:0x%x", rc ^ TRUE); |
Denis Vlasenko | b04b435 | 2007-04-08 11:10:43 +0000 | [diff] [blame] | 482 | return rc ^ TRUE; /* restore TRUE bit */ |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | |
Denys Vlasenko | b24ef03 | 2011-05-23 00:40:54 +0200 | [diff] [blame] | 486 | #if !FNM_CASEFOLD |
| 487 | static char *strcpy_upcase(char *dst, const char *src) |
| 488 | { |
| 489 | char *d = dst; |
| 490 | while (1) { |
| 491 | unsigned char ch = *src++; |
| 492 | if (ch >= 'a' && ch <= 'z') |
| 493 | ch -= ('a' - 'A'); |
| 494 | *d++ = ch; |
| 495 | if (ch == '\0') |
| 496 | break; |
| 497 | } |
| 498 | return dst; |
| 499 | } |
| 500 | #endif |
| 501 | |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 502 | ACTF(name) |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 503 | { |
Denis Vlasenko | dc757aa | 2007-06-30 08:04:05 +0000 | [diff] [blame] | 504 | const char *tmp = bb_basename(fileName); |
Denys Vlasenko | 9138817 | 2010-04-26 09:54:04 +0200 | [diff] [blame] | 505 | if (tmp != fileName && *tmp == '\0') { |
| 506 | /* "foo/bar/". Oh no... go back to 'b' */ |
Denis Vlasenko | dc757aa | 2007-06-30 08:04:05 +0000 | [diff] [blame] | 507 | tmp--; |
| 508 | while (tmp != fileName && *--tmp != '/') |
| 509 | continue; |
| 510 | if (*tmp == '/') |
| 511 | tmp++; |
Denis Vlasenko | bbd695d | 2007-04-08 10:52:28 +0000 | [diff] [blame] | 512 | } |
Denys Vlasenko | 9138817 | 2010-04-26 09:54:04 +0200 | [diff] [blame] | 513 | /* Was using FNM_PERIOD flag too, |
| 514 | * but somewhere between 4.1.20 and 4.4.0 GNU find stopped using it. |
| 515 | * find -name '*foo' should match .foo too: |
| 516 | */ |
Denys Vlasenko | b24ef03 | 2011-05-23 00:40:54 +0200 | [diff] [blame] | 517 | #if FNM_CASEFOLD |
Denys Vlasenko | 9138817 | 2010-04-26 09:54:04 +0200 | [diff] [blame] | 518 | return fnmatch(ap->pattern, tmp, (ap->iname ? FNM_CASEFOLD : 0)) == 0; |
Denys Vlasenko | b24ef03 | 2011-05-23 00:40:54 +0200 | [diff] [blame] | 519 | #else |
| 520 | if (ap->iname) |
| 521 | tmp = strcpy_upcase(alloca(strlen(tmp) + 1), tmp); |
| 522 | return fnmatch(ap->pattern, tmp, 0) == 0; |
| 523 | #endif |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 524 | } |
Denis Vlasenko | 75aa615 | 2007-12-09 10:07:39 +0000 | [diff] [blame] | 525 | |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 526 | #if ENABLE_FEATURE_FIND_PATH |
| 527 | ACTF(path) |
| 528 | { |
Denys Vlasenko | b24ef03 | 2011-05-23 00:40:54 +0200 | [diff] [blame] | 529 | # if FNM_CASEFOLD |
Bogdan Harjoc | 7948ecb | 2011-05-22 03:50:21 +0200 | [diff] [blame] | 530 | return fnmatch(ap->pattern, fileName, (ap->ipath ? FNM_CASEFOLD : 0)) == 0; |
Denys Vlasenko | b24ef03 | 2011-05-23 00:40:54 +0200 | [diff] [blame] | 531 | # else |
| 532 | if (ap->ipath) |
| 533 | fileName = strcpy_upcase(alloca(strlen(fileName) + 1), fileName); |
| 534 | return fnmatch(ap->pattern, fileName, 0) == 0; |
| 535 | # endif |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 536 | } |
| 537 | #endif |
| 538 | #if ENABLE_FEATURE_FIND_REGEX |
| 539 | ACTF(regex) |
| 540 | { |
| 541 | regmatch_t match; |
| 542 | if (regexec(&ap->compiled_pattern, fileName, 1, &match, 0 /*eflags*/)) |
| 543 | return 0; /* no match */ |
| 544 | if (match.rm_so) |
| 545 | return 0; /* match doesn't start at pos 0 */ |
| 546 | if (fileName[match.rm_eo]) |
| 547 | return 0; /* match doesn't end exactly at end of pathname */ |
| 548 | return 1; |
| 549 | } |
| 550 | #endif |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 551 | #if ENABLE_FEATURE_FIND_TYPE |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 552 | ACTF(type) |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 553 | { |
Denis Vlasenko | 31c65f2 | 2006-10-31 23:39:37 +0000 | [diff] [blame] | 554 | return ((statbuf->st_mode & S_IFMT) == ap->type_mask); |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 555 | } |
Rob Landley | cee605c | 2005-10-06 16:39:17 +0000 | [diff] [blame] | 556 | #endif |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 557 | #if ENABLE_FEATURE_FIND_PERM |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 558 | ACTF(perm) |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 559 | { |
Denis Vlasenko | fc7f922 | 2007-01-26 23:00:05 +0000 | [diff] [blame] | 560 | /* -perm +mode: at least one of perm_mask bits are set */ |
| 561 | if (ap->perm_char == '+') |
| 562 | return (statbuf->st_mode & ap->perm_mask) != 0; |
| 563 | /* -perm -mode: all of perm_mask are set */ |
| 564 | if (ap->perm_char == '-') |
| 565 | return (statbuf->st_mode & ap->perm_mask) == ap->perm_mask; |
| 566 | /* -perm mode: file mode must match perm_mask */ |
| 567 | return (statbuf->st_mode & 07777) == ap->perm_mask; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 568 | } |
Rob Landley | cee605c | 2005-10-06 16:39:17 +0000 | [diff] [blame] | 569 | #endif |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 570 | #if ENABLE_FEATURE_FIND_MTIME |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 571 | ACTF(mtime) |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 572 | { |
| 573 | time_t file_age = time(NULL) - statbuf->st_mtime; |
Denis Vlasenko | fc7f922 | 2007-01-26 23:00:05 +0000 | [diff] [blame] | 574 | time_t mtime_secs = ap->mtime_days * 24*60*60; |
| 575 | if (ap->mtime_char == '+') |
| 576 | return file_age >= mtime_secs + 24*60*60; |
| 577 | if (ap->mtime_char == '-') |
| 578 | return file_age < mtime_secs; |
| 579 | /* just numeric mtime */ |
| 580 | return file_age >= mtime_secs && file_age < (mtime_secs + 24*60*60); |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 581 | } |
Rob Landley | cee605c | 2005-10-06 16:39:17 +0000 | [diff] [blame] | 582 | #endif |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 583 | #if ENABLE_FEATURE_FIND_MMIN |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 584 | ACTF(mmin) |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 585 | { |
| 586 | time_t file_age = time(NULL) - statbuf->st_mtime; |
| 587 | time_t mmin_secs = ap->mmin_mins * 60; |
Denis Vlasenko | fc7f922 | 2007-01-26 23:00:05 +0000 | [diff] [blame] | 588 | if (ap->mmin_char == '+') |
| 589 | return file_age >= mmin_secs + 60; |
| 590 | if (ap->mmin_char == '-') |
| 591 | return file_age < mmin_secs; |
| 592 | /* just numeric mmin */ |
| 593 | return file_age >= mmin_secs && file_age < (mmin_secs + 60); |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 594 | } |
Paul Fox | 72d1a23 | 2006-01-13 21:05:41 +0000 | [diff] [blame] | 595 | #endif |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 596 | #if ENABLE_FEATURE_FIND_NEWER |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 597 | ACTF(newer) |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 598 | { |
Denis Vlasenko | fc7f922 | 2007-01-26 23:00:05 +0000 | [diff] [blame] | 599 | return (ap->newer_mtime < statbuf->st_mtime); |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 600 | } |
Rob Landley | cee605c | 2005-10-06 16:39:17 +0000 | [diff] [blame] | 601 | #endif |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 602 | #if ENABLE_FEATURE_FIND_INUM |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 603 | ACTF(inum) |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 604 | { |
Denis Vlasenko | fc7f922 | 2007-01-26 23:00:05 +0000 | [diff] [blame] | 605 | return (statbuf->st_ino == ap->inode_num); |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 606 | } |
Rob Landley | cee605c | 2005-10-06 16:39:17 +0000 | [diff] [blame] | 607 | #endif |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 608 | #if ENABLE_FEATURE_FIND_EXEC |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 609 | ACTF(exec) |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 610 | { |
| 611 | int i, rc; |
Denys Vlasenko | aa7da73 | 2009-09-13 14:57:24 +0200 | [diff] [blame] | 612 | #if ENABLE_USE_PORTABLE_CODE |
| 613 | char **argv = alloca(sizeof(char*) * (ap->exec_argc + 1)); |
| 614 | #else /* gcc 4.3.1 generates smaller code: */ |
Denis Vlasenko | cd7001f | 2007-04-09 21:32:30 +0000 | [diff] [blame] | 615 | char *argv[ap->exec_argc + 1]; |
Denys Vlasenko | aa7da73 | 2009-09-13 14:57:24 +0200 | [diff] [blame] | 616 | #endif |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 617 | for (i = 0; i < ap->exec_argc; i++) |
| 618 | argv[i] = subst(ap->exec_argv[i], ap->subst_count[i], fileName); |
| 619 | argv[i] = NULL; /* terminate the list */ |
Denis Vlasenko | 7e754f1 | 2007-04-09 13:04:50 +0000 | [diff] [blame] | 620 | |
Denis Vlasenko | cd7001f | 2007-04-09 21:32:30 +0000 | [diff] [blame] | 621 | rc = spawn_and_wait(argv); |
Denis Vlasenko | 7e754f1 | 2007-04-09 13:04:50 +0000 | [diff] [blame] | 622 | if (rc < 0) |
Denis Vlasenko | 0c97c9d | 2007-10-01 11:58:38 +0000 | [diff] [blame] | 623 | bb_simple_perror_msg(argv[0]); |
Denis Vlasenko | cd7001f | 2007-04-09 21:32:30 +0000 | [diff] [blame] | 624 | |
| 625 | i = 0; |
| 626 | while (argv[i]) |
| 627 | free(argv[i++]); |
| 628 | return rc == 0; /* return 1 if exitcode 0 */ |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 629 | } |
Rob Landley | cee605c | 2005-10-06 16:39:17 +0000 | [diff] [blame] | 630 | #endif |
Denis Vlasenko | a100707 | 2007-02-02 01:17:52 +0000 | [diff] [blame] | 631 | #if ENABLE_FEATURE_FIND_USER |
| 632 | ACTF(user) |
| 633 | { |
| 634 | return (statbuf->st_uid == ap->uid); |
| 635 | } |
| 636 | #endif |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 637 | #if ENABLE_FEATURE_FIND_GROUP |
| 638 | ACTF(group) |
| 639 | { |
| 640 | return (statbuf->st_gid == ap->gid); |
| 641 | } |
| 642 | #endif |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 643 | #if ENABLE_FEATURE_FIND_PRINT0 |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 644 | ACTF(print0) |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 645 | { |
| 646 | printf("%s%c", fileName, '\0'); |
Denis Vlasenko | 3a6755f | 2006-10-14 14:24:30 +0000 | [diff] [blame] | 647 | return TRUE; |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 648 | } |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 649 | #endif |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 650 | ACTF(print) |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 651 | { |
| 652 | puts(fileName); |
| 653 | return TRUE; |
| 654 | } |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 655 | #if ENABLE_FEATURE_FIND_PAREN |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 656 | ACTF(paren) |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 657 | { |
| 658 | return exec_actions(ap->subexpr, fileName, statbuf); |
| 659 | } |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 660 | #endif |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 661 | #if ENABLE_FEATURE_FIND_SIZE |
| 662 | ACTF(size) |
| 663 | { |
Denis Vlasenko | 53a0e97 | 2007-06-16 00:30:52 +0000 | [diff] [blame] | 664 | if (ap->size_char == '+') |
| 665 | return statbuf->st_size > ap->size; |
| 666 | if (ap->size_char == '-') |
| 667 | return statbuf->st_size < ap->size; |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 668 | return statbuf->st_size == ap->size; |
| 669 | } |
| 670 | #endif |
Bernhard Reutner-Fischer | 6d79dd6 | 2007-04-05 09:40:12 +0000 | [diff] [blame] | 671 | #if ENABLE_FEATURE_FIND_PRUNE |
Denis Vlasenko | 5f18e7c | 2006-10-31 03:21:02 +0000 | [diff] [blame] | 672 | /* |
| 673 | * -prune: if -depth is not given, return true and do not descend |
| 674 | * current dir; if -depth is given, return false with no effect. |
| 675 | * Example: |
| 676 | * find dir -name 'asm-*' -prune -o -name '*.[chS]' -print |
| 677 | */ |
Denis Vlasenko | 9225854 | 2006-11-01 10:25:35 +0000 | [diff] [blame] | 678 | ACTF(prune) |
Denis Vlasenko | 5f18e7c | 2006-10-31 03:21:02 +0000 | [diff] [blame] | 679 | { |
Denis Vlasenko | bbd695d | 2007-04-08 10:52:28 +0000 | [diff] [blame] | 680 | return SKIP + TRUE; |
Denis Vlasenko | 5f18e7c | 2006-10-31 03:21:02 +0000 | [diff] [blame] | 681 | } |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 682 | #endif |
Denis Vlasenko | 62f0479 | 2007-04-13 10:00:12 +0000 | [diff] [blame] | 683 | #if ENABLE_FEATURE_FIND_DELETE |
| 684 | ACTF(delete) |
| 685 | { |
| 686 | int rc; |
| 687 | if (S_ISDIR(statbuf->st_mode)) { |
| 688 | rc = rmdir(fileName); |
| 689 | } else { |
| 690 | rc = unlink(fileName); |
| 691 | } |
| 692 | if (rc < 0) |
Denis Vlasenko | 0c97c9d | 2007-10-01 11:58:38 +0000 | [diff] [blame] | 693 | bb_simple_perror_msg(fileName); |
Denis Vlasenko | 62f0479 | 2007-04-13 10:00:12 +0000 | [diff] [blame] | 694 | return TRUE; |
| 695 | } |
| 696 | #endif |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 697 | #if ENABLE_FEATURE_FIND_CONTEXT |
| 698 | ACTF(context) |
| 699 | { |
| 700 | security_context_t con; |
| 701 | int rc; |
| 702 | |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 703 | if (G.recurse_flags & ACTION_FOLLOWLINKS) { |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 704 | rc = getfilecon(fileName, &con); |
| 705 | } else { |
| 706 | rc = lgetfilecon(fileName, &con); |
| 707 | } |
| 708 | if (rc < 0) |
| 709 | return FALSE; |
| 710 | rc = strcmp(ap->context, con); |
| 711 | freecon(con); |
| 712 | return rc == 0; |
| 713 | } |
| 714 | #endif |
Matheus Izvekov | d0f601f | 2010-01-06 09:19:04 +0100 | [diff] [blame] | 715 | #if ENABLE_FEATURE_FIND_LINKS |
| 716 | ACTF(links) |
| 717 | { |
| 718 | switch(ap->links_char) { |
| 719 | case '-' : return (statbuf->st_nlink < ap->links_count); |
| 720 | case '+' : return (statbuf->st_nlink > ap->links_count); |
| 721 | default: return (statbuf->st_nlink == ap->links_count); |
| 722 | } |
| 723 | } |
| 724 | #endif |
Denis Vlasenko | 62f0479 | 2007-04-13 10:00:12 +0000 | [diff] [blame] | 725 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 726 | static int FAST_FUNC fileAction(const char *fileName, |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 727 | struct stat *statbuf, |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 728 | void *userData UNUSED_PARAM, |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 729 | int depth IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM)) |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 730 | { |
Denys Vlasenko | ce9b97f | 2010-01-10 02:33:02 +0100 | [diff] [blame] | 731 | int r; |
Denys Vlasenko | 2dc1a97 | 2012-09-06 15:24:11 +0200 | [diff] [blame] | 732 | int same_fs = 1; |
| 733 | |
| 734 | #if ENABLE_FEATURE_FIND_XDEV |
| 735 | if (S_ISDIR(statbuf->st_mode) && G.xdev_count) { |
| 736 | int i; |
| 737 | for (i = 0; i < G.xdev_count; i++) { |
| 738 | if (G.xdev_dev[i] == statbuf->st_dev) |
| 739 | goto found; |
| 740 | } |
| 741 | //bb_error_msg("'%s': not same fs", fileName); |
| 742 | same_fs = 0; |
| 743 | found: ; |
| 744 | } |
| 745 | #endif |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 746 | |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 747 | #if ENABLE_FEATURE_FIND_MAXDEPTH |
Denys Vlasenko | 2dc1a97 | 2012-09-06 15:24:11 +0200 | [diff] [blame] | 748 | if (depth < G.minmaxdepth[0]) { |
| 749 | if (same_fs) |
| 750 | return TRUE; /* skip this, continue recursing */ |
| 751 | return SKIP; /* stop recursing */ |
| 752 | } |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 753 | if (depth > G.minmaxdepth[1]) |
Denys Vlasenko | ce9b97f | 2010-01-10 02:33:02 +0100 | [diff] [blame] | 754 | return SKIP; /* stop recursing */ |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 755 | #endif |
| 756 | |
Denys Vlasenko | ce9b97f | 2010-01-10 02:33:02 +0100 | [diff] [blame] | 757 | r = exec_actions(G.actions, fileName, statbuf); |
| 758 | /* Had no explicit -print[0] or -exec? then print */ |
| 759 | if ((r & TRUE) && G.need_print) |
| 760 | puts(fileName); |
| 761 | |
| 762 | #if ENABLE_FEATURE_FIND_MAXDEPTH |
| 763 | if (S_ISDIR(statbuf->st_mode)) { |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 764 | if (depth == G.minmaxdepth[1]) |
Denys Vlasenko | ce9b97f | 2010-01-10 02:33:02 +0100 | [diff] [blame] | 765 | return SKIP; |
| 766 | } |
| 767 | #endif |
Denys Vlasenko | ce9b97f | 2010-01-10 02:33:02 +0100 | [diff] [blame] | 768 | /* -xdev stops on mountpoints, but AFTER mountpoit itself |
| 769 | * is processed as usual */ |
Denys Vlasenko | 2dc1a97 | 2012-09-06 15:24:11 +0200 | [diff] [blame] | 770 | if (!same_fs) { |
| 771 | return SKIP; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 772 | } |
Denys Vlasenko | 6c750f1 | 2009-09-27 01:51:47 +0200 | [diff] [blame] | 773 | |
Denis Vlasenko | 5f18e7c | 2006-10-31 03:21:02 +0000 | [diff] [blame] | 774 | /* Cannot return 0: our caller, recursive_action(), |
| 775 | * will perror() and skip dirs (if called on dir) */ |
Denys Vlasenko | ce9b97f | 2010-01-10 02:33:02 +0100 | [diff] [blame] | 776 | return (r & SKIP) ? SKIP : TRUE; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 779 | |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 780 | #if ENABLE_FEATURE_FIND_TYPE |
Denis Vlasenko | 434ad54 | 2007-01-27 13:45:17 +0000 | [diff] [blame] | 781 | static int find_type(const char *type) |
Matt Kraai | 096370d | 2001-02-07 03:52:38 +0000 | [diff] [blame] | 782 | { |
| 783 | int mask = 0; |
| 784 | |
Bernhard Reutner-Fischer | 307d27d | 2007-03-29 13:56:02 +0000 | [diff] [blame] | 785 | if (*type == 'b') |
Denis Vlasenko | 3a6755f | 2006-10-14 14:24:30 +0000 | [diff] [blame] | 786 | mask = S_IFBLK; |
Bernhard Reutner-Fischer | 307d27d | 2007-03-29 13:56:02 +0000 | [diff] [blame] | 787 | else if (*type == 'c') |
Denis Vlasenko | 3a6755f | 2006-10-14 14:24:30 +0000 | [diff] [blame] | 788 | mask = S_IFCHR; |
Bernhard Reutner-Fischer | 307d27d | 2007-03-29 13:56:02 +0000 | [diff] [blame] | 789 | else if (*type == 'd') |
Denis Vlasenko | 3a6755f | 2006-10-14 14:24:30 +0000 | [diff] [blame] | 790 | mask = S_IFDIR; |
Bernhard Reutner-Fischer | 307d27d | 2007-03-29 13:56:02 +0000 | [diff] [blame] | 791 | else if (*type == 'p') |
Denis Vlasenko | 3a6755f | 2006-10-14 14:24:30 +0000 | [diff] [blame] | 792 | mask = S_IFIFO; |
Bernhard Reutner-Fischer | 307d27d | 2007-03-29 13:56:02 +0000 | [diff] [blame] | 793 | else if (*type == 'f') |
Denis Vlasenko | 3a6755f | 2006-10-14 14:24:30 +0000 | [diff] [blame] | 794 | mask = S_IFREG; |
Bernhard Reutner-Fischer | 307d27d | 2007-03-29 13:56:02 +0000 | [diff] [blame] | 795 | else if (*type == 'l') |
Denis Vlasenko | 3a6755f | 2006-10-14 14:24:30 +0000 | [diff] [blame] | 796 | mask = S_IFLNK; |
Bernhard Reutner-Fischer | 307d27d | 2007-03-29 13:56:02 +0000 | [diff] [blame] | 797 | else if (*type == 's') |
Denis Vlasenko | 3a6755f | 2006-10-14 14:24:30 +0000 | [diff] [blame] | 798 | mask = S_IFSOCK; |
Matt Kraai | 096370d | 2001-02-07 03:52:38 +0000 | [diff] [blame] | 799 | |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 800 | if (mask == 0 || type[1] != '\0') |
Bernhard Reutner-Fischer | 19008b8 | 2006-06-07 20:17:41 +0000 | [diff] [blame] | 801 | bb_error_msg_and_die(bb_msg_invalid_arg, type, "-type"); |
Matt Kraai | 096370d | 2001-02-07 03:52:38 +0000 | [diff] [blame] | 802 | |
| 803 | return mask; |
| 804 | } |
| 805 | #endif |
| 806 | |
Denis Vlasenko | 4b9b0ce | 2007-07-01 17:35:17 +0000 | [diff] [blame] | 807 | #if ENABLE_FEATURE_FIND_PERM \ |
| 808 | || ENABLE_FEATURE_FIND_MTIME || ENABLE_FEATURE_FIND_MMIN \ |
Matheus Izvekov | d0f601f | 2010-01-06 09:19:04 +0100 | [diff] [blame] | 809 | || ENABLE_FEATURE_FIND_SIZE || ENABLE_FEATURE_FIND_LINKS |
Denis Vlasenko | fc7f922 | 2007-01-26 23:00:05 +0000 | [diff] [blame] | 810 | static const char* plus_minus_num(const char* str) |
| 811 | { |
| 812 | if (*str == '-' || *str == '+') |
| 813 | str++; |
| 814 | return str; |
| 815 | } |
Denis Vlasenko | 4c97863 | 2007-02-03 03:31:13 +0000 | [diff] [blame] | 816 | #endif |
Denis Vlasenko | fc7f922 | 2007-01-26 23:00:05 +0000 | [diff] [blame] | 817 | |
Denys Vlasenko | 6db5f67 | 2013-05-16 18:36:42 +0200 | [diff] [blame] | 818 | /* Say no to GCCism */ |
| 819 | #define USE_NESTED_FUNCTION 0 |
| 820 | |
| 821 | #if !USE_NESTED_FUNCTION |
| 822 | struct pp_locals { |
| 823 | action*** appp; |
| 824 | unsigned cur_group; |
| 825 | unsigned cur_action; |
| 826 | IF_FEATURE_FIND_NOT( bool invert_flag; ) |
| 827 | }; |
| 828 | static action* alloc_action(struct pp_locals *ppl, int sizeof_struct, action_fp f) |
| 829 | { |
| 830 | action *ap = xzalloc(sizeof_struct); |
| 831 | action **app; |
| 832 | action ***group = &ppl->appp[ppl->cur_group]; |
| 833 | *group = app = xrealloc(*group, (ppl->cur_action+2) * sizeof(ppl->appp[0][0])); |
| 834 | app[ppl->cur_action++] = ap; |
| 835 | app[ppl->cur_action] = NULL; |
| 836 | ap->f = f; |
| 837 | IF_FEATURE_FIND_NOT( ap->invert = ppl->invert_flag; ) |
| 838 | IF_FEATURE_FIND_NOT( ppl->invert_flag = 0; ) |
| 839 | return ap; |
| 840 | } |
| 841 | #endif |
| 842 | |
Denis Vlasenko | 769d1e0 | 2007-01-22 23:04:27 +0000 | [diff] [blame] | 843 | static action*** parse_params(char **argv) |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 844 | { |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 845 | enum { |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 846 | OPT_FOLLOW , |
| 847 | IF_FEATURE_FIND_XDEV( OPT_XDEV ,) |
| 848 | IF_FEATURE_FIND_DEPTH( OPT_DEPTH ,) |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 849 | PARM_a , |
| 850 | PARM_o , |
| 851 | IF_FEATURE_FIND_NOT( PARM_char_not ,) |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 852 | #if ENABLE_DESKTOP |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 853 | PARM_and , |
| 854 | PARM_or , |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 855 | IF_FEATURE_FIND_NOT( PARM_not ,) |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 856 | #endif |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 857 | PARM_print , |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 858 | IF_FEATURE_FIND_PRINT0( PARM_print0 ,) |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 859 | IF_FEATURE_FIND_PRUNE( PARM_prune ,) |
| 860 | IF_FEATURE_FIND_DELETE( PARM_delete ,) |
| 861 | IF_FEATURE_FIND_EXEC( PARM_exec ,) |
| 862 | IF_FEATURE_FIND_PAREN( PARM_char_brace,) |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 863 | /* All options/actions starting from here require argument */ |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 864 | PARM_name , |
| 865 | PARM_iname , |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 866 | IF_FEATURE_FIND_PATH( PARM_path ,) |
Denys Vlasenko | be1cfee | 2012-05-17 12:25:25 +0200 | [diff] [blame] | 867 | #if ENABLE_DESKTOP |
| 868 | /* -wholename is a synonym for -path */ |
Denys Vlasenko | 7c8aa2b | 2012-05-18 02:53:11 +0200 | [diff] [blame] | 869 | /* We support it because Linux kernel's "make tags" uses it */ |
Denys Vlasenko | be1cfee | 2012-05-17 12:25:25 +0200 | [diff] [blame] | 870 | IF_FEATURE_FIND_PATH( PARM_wholename ,) |
| 871 | #endif |
Bogdan Harjoc | 7948ecb | 2011-05-22 03:50:21 +0200 | [diff] [blame] | 872 | IF_FEATURE_FIND_PATH( PARM_ipath ,) |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 873 | IF_FEATURE_FIND_REGEX( PARM_regex ,) |
| 874 | IF_FEATURE_FIND_TYPE( PARM_type ,) |
| 875 | IF_FEATURE_FIND_PERM( PARM_perm ,) |
| 876 | IF_FEATURE_FIND_MTIME( PARM_mtime ,) |
| 877 | IF_FEATURE_FIND_MMIN( PARM_mmin ,) |
| 878 | IF_FEATURE_FIND_NEWER( PARM_newer ,) |
| 879 | IF_FEATURE_FIND_INUM( PARM_inum ,) |
| 880 | IF_FEATURE_FIND_USER( PARM_user ,) |
| 881 | IF_FEATURE_FIND_GROUP( PARM_group ,) |
| 882 | IF_FEATURE_FIND_SIZE( PARM_size ,) |
| 883 | IF_FEATURE_FIND_CONTEXT(PARM_context ,) |
Matheus Izvekov | d0f601f | 2010-01-06 09:19:04 +0100 | [diff] [blame] | 884 | IF_FEATURE_FIND_LINKS( PARM_links ,) |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 885 | IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,OPT_MAXDEPTH,) |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 886 | }; |
| 887 | |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 888 | static const char params[] ALIGN1 = |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 889 | "-follow\0" |
| 890 | IF_FEATURE_FIND_XDEV( "-xdev\0" ) |
| 891 | IF_FEATURE_FIND_DEPTH( "-depth\0" ) |
| 892 | "-a\0" |
| 893 | "-o\0" |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 894 | IF_FEATURE_FIND_NOT( "!\0" ) |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 895 | #if ENABLE_DESKTOP |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 896 | "-and\0" |
| 897 | "-or\0" |
| 898 | IF_FEATURE_FIND_NOT( "-not\0" ) |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 899 | #endif |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 900 | "-print\0" |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 901 | IF_FEATURE_FIND_PRINT0( "-print0\0" ) |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 902 | IF_FEATURE_FIND_PRUNE( "-prune\0" ) |
| 903 | IF_FEATURE_FIND_DELETE( "-delete\0" ) |
| 904 | IF_FEATURE_FIND_EXEC( "-exec\0" ) |
| 905 | IF_FEATURE_FIND_PAREN( "(\0" ) |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 906 | /* All options/actions starting from here require argument */ |
Denys Vlasenko | 6967578 | 2013-01-14 01:34:48 +0100 | [diff] [blame] | 907 | "-name\0" |
| 908 | "-iname\0" |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 909 | IF_FEATURE_FIND_PATH( "-path\0" ) |
Denys Vlasenko | be1cfee | 2012-05-17 12:25:25 +0200 | [diff] [blame] | 910 | #if ENABLE_DESKTOP |
| 911 | IF_FEATURE_FIND_PATH( "-wholename\0") |
| 912 | #endif |
Bogdan Harjoc | 7948ecb | 2011-05-22 03:50:21 +0200 | [diff] [blame] | 913 | IF_FEATURE_FIND_PATH( "-ipath\0" ) |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 914 | IF_FEATURE_FIND_REGEX( "-regex\0" ) |
| 915 | IF_FEATURE_FIND_TYPE( "-type\0" ) |
| 916 | IF_FEATURE_FIND_PERM( "-perm\0" ) |
| 917 | IF_FEATURE_FIND_MTIME( "-mtime\0" ) |
| 918 | IF_FEATURE_FIND_MMIN( "-mmin\0" ) |
| 919 | IF_FEATURE_FIND_NEWER( "-newer\0" ) |
| 920 | IF_FEATURE_FIND_INUM( "-inum\0" ) |
| 921 | IF_FEATURE_FIND_USER( "-user\0" ) |
| 922 | IF_FEATURE_FIND_GROUP( "-group\0" ) |
| 923 | IF_FEATURE_FIND_SIZE( "-size\0" ) |
| 924 | IF_FEATURE_FIND_CONTEXT("-context\0") |
Matheus Izvekov | d0f601f | 2010-01-06 09:19:04 +0100 | [diff] [blame] | 925 | IF_FEATURE_FIND_LINKS( "-links\0" ) |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 926 | IF_FEATURE_FIND_MAXDEPTH("-mindepth\0""-maxdepth\0") |
Denys Vlasenko | cef85c2 | 2011-02-12 16:35:24 +0100 | [diff] [blame] | 927 | ; |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 928 | |
Denys Vlasenko | 6db5f67 | 2013-05-16 18:36:42 +0200 | [diff] [blame] | 929 | #if !USE_NESTED_FUNCTION |
| 930 | struct pp_locals ppl; |
| 931 | #define appp (ppl.appp ) |
| 932 | #define cur_group (ppl.cur_group ) |
| 933 | #define cur_action (ppl.cur_action ) |
| 934 | #define invert_flag (ppl.invert_flag) |
| 935 | #define ALLOC_ACTION(name) (action_##name*)alloc_action(&ppl, sizeof(action_##name), (action_fp) func_##name) |
| 936 | #else |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 937 | action*** appp; |
Denys Vlasenko | 6db5f67 | 2013-05-16 18:36:42 +0200 | [diff] [blame] | 938 | unsigned cur_group; |
| 939 | unsigned cur_action; |
| 940 | IF_FEATURE_FIND_NOT( bool invert_flag; ) |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 941 | |
Denis Vlasenko | 0f3a580 | 2008-03-20 13:13:09 +0000 | [diff] [blame] | 942 | /* This is the only place in busybox where we use nested function. |
| 943 | * So far more standard alternatives were bigger. */ |
Denys Vlasenko | a61ff51 | 2010-08-31 19:17:42 +0200 | [diff] [blame] | 944 | /* Auto decl suppresses "func without a prototype" warning: */ |
Denis Vlasenko | 0f3a580 | 2008-03-20 13:13:09 +0000 | [diff] [blame] | 945 | auto action* alloc_action(int sizeof_struct, action_fp f); |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 946 | action* alloc_action(int sizeof_struct, action_fp f) |
| 947 | { |
| 948 | action *ap; |
Denys Vlasenko | 6db5f67 | 2013-05-16 18:36:42 +0200 | [diff] [blame] | 949 | appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(appp[0][0])); |
Denys Vlasenko | a61ff51 | 2010-08-31 19:17:42 +0200 | [diff] [blame] | 950 | appp[cur_group][cur_action++] = ap = xzalloc(sizeof_struct); |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 951 | appp[cur_group][cur_action] = NULL; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 952 | ap->f = f; |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 953 | IF_FEATURE_FIND_NOT( ap->invert = invert_flag; ) |
| 954 | IF_FEATURE_FIND_NOT( invert_flag = 0; ) |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 955 | return ap; |
| 956 | } |
| 957 | #define ALLOC_ACTION(name) (action_##name*)alloc_action(sizeof(action_##name), (action_fp) func_##name) |
Denys Vlasenko | 6db5f67 | 2013-05-16 18:36:42 +0200 | [diff] [blame] | 958 | #endif |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 959 | |
Denys Vlasenko | 6db5f67 | 2013-05-16 18:36:42 +0200 | [diff] [blame] | 960 | cur_group = 0; |
| 961 | cur_action = 0; |
| 962 | IF_FEATURE_FIND_NOT( invert_flag = 0; ) |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 963 | appp = xzalloc(2 * sizeof(appp[0])); /* appp[0],[1] == NULL */ |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 964 | |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 965 | while (*argv) { |
Denis Vlasenko | 434ad54 | 2007-01-27 13:45:17 +0000 | [diff] [blame] | 966 | const char *arg = argv[0]; |
Denis Vlasenko | 990d0f6 | 2007-07-24 15:54:42 +0000 | [diff] [blame] | 967 | int parm = index_in_strings(params, arg); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 968 | const char *arg1 = argv[1]; |
| 969 | |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 970 | dbg("arg:'%s' arg1:'%s' parm:%d PARM_type:%d", arg, arg1, parm, PARM_type); |
| 971 | |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 972 | if (parm >= PARM_name) { |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 973 | /* All options/actions starting from -name require argument */ |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 974 | if (!arg1) |
| 975 | bb_error_msg_and_die(bb_msg_requires_arg, arg); |
| 976 | argv++; |
| 977 | } |
| 978 | |
| 979 | /* We can use big switch() here, but on i386 |
| 980 | * it doesn't give smaller code. Other arches? */ |
| 981 | |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 982 | /* Options always return true. They always take effect |
| 983 | * rather than being processed only when their place in the |
| 984 | * expression is reached. |
| 985 | */ |
| 986 | /* Options */ |
Ian Wienand | abc33ac | 2011-08-28 06:53:20 +0200 | [diff] [blame] | 987 | if (parm == OPT_FOLLOW) { |
Denys Vlasenko | 982e87f | 2013-07-30 11:52:58 +0200 | [diff] [blame] | 988 | dbg("follow enabled: %d", __LINE__); |
| 989 | G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK; |
Ian Wienand | abc33ac | 2011-08-28 06:53:20 +0200 | [diff] [blame] | 990 | } |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 991 | #if ENABLE_FEATURE_FIND_XDEV |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 992 | else if (parm == OPT_XDEV) { |
| 993 | dbg("%d", __LINE__); |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 994 | G.xdev_on = 1; |
| 995 | } |
| 996 | #endif |
| 997 | #if ENABLE_FEATURE_FIND_MAXDEPTH |
| 998 | else if (parm == OPT_MINDEPTH || parm == OPT_MINDEPTH + 1) { |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 999 | dbg("%d", __LINE__); |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1000 | G.minmaxdepth[parm - OPT_MINDEPTH] = xatoi_positive(arg1); |
| 1001 | } |
| 1002 | #endif |
| 1003 | #if ENABLE_FEATURE_FIND_DEPTH |
| 1004 | else if (parm == OPT_DEPTH) { |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1005 | dbg("%d", __LINE__); |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1006 | G.recurse_flags |= ACTION_DEPTHFIRST; |
| 1007 | } |
| 1008 | #endif |
| 1009 | /* Actions are grouped by operators |
| 1010 | * ( expr ) Force precedence |
| 1011 | * ! expr True if expr is false |
| 1012 | * -not expr Same as ! expr |
| 1013 | * expr1 [-a[nd]] expr2 And; expr2 is not evaluated if expr1 is false |
| 1014 | * expr1 -o[r] expr2 Or; expr2 is not evaluated if expr1 is true |
| 1015 | * expr1 , expr2 List; both expr1 and expr2 are always evaluated |
| 1016 | * We implement: (), -a, -o |
| 1017 | */ |
| 1018 | /* Operators */ |
| 1019 | else if (parm == PARM_a IF_DESKTOP(|| parm == PARM_and)) { |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1020 | dbg("%d", __LINE__); |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 1021 | /* no further special handling required */ |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1022 | } |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 1023 | else if (parm == PARM_o IF_DESKTOP(|| parm == PARM_or)) { |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1024 | dbg("%d", __LINE__); |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1025 | /* start new OR group */ |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1026 | cur_group++; |
Denys Vlasenko | 6db5f67 | 2013-05-16 18:36:42 +0200 | [diff] [blame] | 1027 | appp = xrealloc(appp, (cur_group+2) * sizeof(appp[0])); |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 1028 | /*appp[cur_group] = NULL; - already NULL */ |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1029 | appp[cur_group+1] = NULL; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1030 | cur_action = 0; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1031 | } |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 1032 | #if ENABLE_FEATURE_FIND_NOT |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 1033 | else if (parm == PARM_char_not IF_DESKTOP(|| parm == PARM_not)) { |
Denis Vlasenko | b292264 | 2007-02-06 17:38:29 +0000 | [diff] [blame] | 1034 | /* also handles "find ! ! -name 'foo*'" */ |
| 1035 | invert_flag ^= 1; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1036 | dbg("invert_flag:%d", invert_flag); |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 1037 | } |
| 1038 | #endif |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1039 | /* Actions */ |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 1040 | else if (parm == PARM_print) { |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1041 | dbg("%d", __LINE__); |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 1042 | G.need_print = 0; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1043 | (void) ALLOC_ACTION(print); |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 1044 | } |
| 1045 | #if ENABLE_FEATURE_FIND_PRINT0 |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 1046 | else if (parm == PARM_print0) { |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1047 | dbg("%d", __LINE__); |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 1048 | G.need_print = 0; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1049 | (void) ALLOC_ACTION(print0); |
| 1050 | } |
Paul Fox | d738429 | 2006-05-12 14:47:20 +0000 | [diff] [blame] | 1051 | #endif |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1052 | #if ENABLE_FEATURE_FIND_PRUNE |
| 1053 | else if (parm == PARM_prune) { |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1054 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1055 | (void) ALLOC_ACTION(prune); |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 1056 | } |
| 1057 | #endif |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1058 | #if ENABLE_FEATURE_FIND_DELETE |
| 1059 | else if (parm == PARM_delete) { |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1060 | dbg("%d", __LINE__); |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 1061 | G.need_print = 0; |
| 1062 | G.recurse_flags |= ACTION_DEPTHFIRST; |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1063 | (void) ALLOC_ACTION(delete); |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1064 | } |
Rob Landley | cee605c | 2005-10-06 16:39:17 +0000 | [diff] [blame] | 1065 | #endif |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 1066 | #if ENABLE_FEATURE_FIND_EXEC |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 1067 | else if (parm == PARM_exec) { |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1068 | int i; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1069 | action_exec *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1070 | dbg("%d", __LINE__); |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 1071 | G.need_print = 0; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1072 | ap = ALLOC_ACTION(exec); |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1073 | ap->exec_argv = ++argv; /* first arg after -exec */ |
Denys Vlasenko | a61ff51 | 2010-08-31 19:17:42 +0200 | [diff] [blame] | 1074 | /*ap->exec_argc = 0; - ALLOC_ACTION did it */ |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 1075 | while (1) { |
Bernhard Reutner-Fischer | 2e73d84 | 2010-02-25 13:22:37 +0100 | [diff] [blame] | 1076 | if (!*argv) /* did not see ';' or '+' until end */ |
| 1077 | bb_error_msg_and_die(bb_msg_requires_arg, "-exec"); |
Denys Vlasenko | a61ff51 | 2010-08-31 19:17:42 +0200 | [diff] [blame] | 1078 | // find -exec echo Foo ">{}<" ";" |
Denys Vlasenko | cef85c2 | 2011-02-12 16:35:24 +0100 | [diff] [blame] | 1079 | // executes "echo Foo >FILENAME<", |
Denys Vlasenko | a61ff51 | 2010-08-31 19:17:42 +0200 | [diff] [blame] | 1080 | // find -exec echo Foo ">{}<" "+" |
Denys Vlasenko | cef85c2 | 2011-02-12 16:35:24 +0100 | [diff] [blame] | 1081 | // executes "echo Foo FILENAME1 FILENAME2 FILENAME3...". |
Denys Vlasenko | a61ff51 | 2010-08-31 19:17:42 +0200 | [diff] [blame] | 1082 | // TODO (so far we treat "+" just like ";") |
| 1083 | if ((argv[0][0] == ';' || argv[0][0] == '+') |
| 1084 | && argv[0][1] == '\0' |
| 1085 | ) { |
Rob Landley | 5d3a0e8 | 2005-10-04 03:34:39 +0000 | [diff] [blame] | 1086 | break; |
Denys Vlasenko | a61ff51 | 2010-08-31 19:17:42 +0200 | [diff] [blame] | 1087 | } |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1088 | argv++; |
| 1089 | ap->exec_argc++; |
Rob Landley | 5d3a0e8 | 2005-10-04 03:34:39 +0000 | [diff] [blame] | 1090 | } |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1091 | if (ap->exec_argc == 0) |
Denis Vlasenko | df0553b | 2006-10-29 00:21:47 +0000 | [diff] [blame] | 1092 | bb_error_msg_and_die(bb_msg_requires_arg, arg); |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1093 | ap->subst_count = xmalloc(ap->exec_argc * sizeof(int)); |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1094 | i = ap->exec_argc; |
| 1095 | while (i--) |
| 1096 | ap->subst_count[i] = count_subst(ap->exec_argv[i]); |
| 1097 | } |
| 1098 | #endif |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 1099 | #if ENABLE_FEATURE_FIND_PAREN |
| 1100 | else if (parm == PARM_char_brace) { |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1101 | action_paren *ap; |
| 1102 | char **endarg; |
Bernhard Reutner-Fischer | 10b7996 | 2007-02-04 16:09:04 +0000 | [diff] [blame] | 1103 | unsigned nested = 1; |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1104 | |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1105 | dbg("%d", __LINE__); |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1106 | endarg = argv; |
| 1107 | while (1) { |
| 1108 | if (!*++endarg) |
| 1109 | bb_error_msg_and_die("unpaired '('"); |
Denis Vlasenko | 9ac9e55 | 2006-12-23 15:58:11 +0000 | [diff] [blame] | 1110 | if (LONE_CHAR(*endarg, '(')) |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1111 | nested++; |
Denis Vlasenko | 9ac9e55 | 2006-12-23 15:58:11 +0000 | [diff] [blame] | 1112 | else if (LONE_CHAR(*endarg, ')') && !--nested) { |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1113 | *endarg = NULL; |
| 1114 | break; |
| 1115 | } |
| 1116 | } |
| 1117 | ap = ALLOC_ACTION(paren); |
| 1118 | ap->subexpr = parse_params(argv + 1); |
Denis Vlasenko | ab2aea4 | 2007-01-29 22:51:58 +0000 | [diff] [blame] | 1119 | *endarg = (char*) ")"; /* restore NULLed parameter */ |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1120 | argv = endarg; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1121 | } |
Denis Vlasenko | 56fce00 | 2007-04-04 23:41:35 +0000 | [diff] [blame] | 1122 | #endif |
Denis Vlasenko | 75aa615 | 2007-12-09 10:07:39 +0000 | [diff] [blame] | 1123 | else if (parm == PARM_name || parm == PARM_iname) { |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1124 | action_name *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1125 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1126 | ap = ALLOC_ACTION(name); |
| 1127 | ap->pattern = arg1; |
Denis Vlasenko | 75aa615 | 2007-12-09 10:07:39 +0000 | [diff] [blame] | 1128 | ap->iname = (parm == PARM_iname); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1129 | } |
| 1130 | #if ENABLE_FEATURE_FIND_PATH |
Denys Vlasenko | be1cfee | 2012-05-17 12:25:25 +0200 | [diff] [blame] | 1131 | else if (parm == PARM_path IF_DESKTOP(|| parm == PARM_wholename) || parm == PARM_ipath) { |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1132 | action_path *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1133 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1134 | ap = ALLOC_ACTION(path); |
| 1135 | ap->pattern = arg1; |
Bogdan Harjoc | 7948ecb | 2011-05-22 03:50:21 +0200 | [diff] [blame] | 1136 | ap->ipath = (parm == PARM_ipath); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1137 | } |
| 1138 | #endif |
| 1139 | #if ENABLE_FEATURE_FIND_REGEX |
| 1140 | else if (parm == PARM_regex) { |
| 1141 | action_regex *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1142 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1143 | ap = ALLOC_ACTION(regex); |
| 1144 | xregcomp(&ap->compiled_pattern, arg1, 0 /*cflags*/); |
| 1145 | } |
| 1146 | #endif |
| 1147 | #if ENABLE_FEATURE_FIND_TYPE |
| 1148 | else if (parm == PARM_type) { |
| 1149 | action_type *ap; |
| 1150 | ap = ALLOC_ACTION(type); |
| 1151 | ap->type_mask = find_type(arg1); |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1152 | dbg("created:type mask:%x", ap->type_mask); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1153 | } |
| 1154 | #endif |
| 1155 | #if ENABLE_FEATURE_FIND_PERM |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1156 | /* -perm BITS File's mode bits are exactly BITS (octal or symbolic). |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1157 | * Symbolic modes use mode 0 as a point of departure. |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1158 | * -perm -BITS All of the BITS are set in file's mode. |
| 1159 | * -perm +BITS At least one of the BITS is set in file's mode. |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1160 | */ |
| 1161 | else if (parm == PARM_perm) { |
| 1162 | action_perm *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1163 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1164 | ap = ALLOC_ACTION(perm); |
| 1165 | ap->perm_char = arg1[0]; |
| 1166 | arg1 = plus_minus_num(arg1); |
Denys Vlasenko | a61ff51 | 2010-08-31 19:17:42 +0200 | [diff] [blame] | 1167 | /*ap->perm_mask = 0; - ALLOC_ACTION did it */ |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1168 | if (!bb_parse_mode(arg1, &ap->perm_mask)) |
Denys Vlasenko | 651a269 | 2010-03-23 16:25:17 +0100 | [diff] [blame] | 1169 | bb_error_msg_and_die("invalid mode '%s'", arg1); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1170 | } |
| 1171 | #endif |
| 1172 | #if ENABLE_FEATURE_FIND_MTIME |
| 1173 | else if (parm == PARM_mtime) { |
| 1174 | action_mtime *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1175 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1176 | ap = ALLOC_ACTION(mtime); |
| 1177 | ap->mtime_char = arg1[0]; |
| 1178 | ap->mtime_days = xatoul(plus_minus_num(arg1)); |
| 1179 | } |
| 1180 | #endif |
| 1181 | #if ENABLE_FEATURE_FIND_MMIN |
| 1182 | else if (parm == PARM_mmin) { |
| 1183 | action_mmin *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1184 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1185 | ap = ALLOC_ACTION(mmin); |
| 1186 | ap->mmin_char = arg1[0]; |
| 1187 | ap->mmin_mins = xatoul(plus_minus_num(arg1)); |
| 1188 | } |
| 1189 | #endif |
| 1190 | #if ENABLE_FEATURE_FIND_NEWER |
| 1191 | else if (parm == PARM_newer) { |
| 1192 | struct stat stat_newer; |
| 1193 | action_newer *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1194 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1195 | ap = ALLOC_ACTION(newer); |
| 1196 | xstat(arg1, &stat_newer); |
| 1197 | ap->newer_mtime = stat_newer.st_mtime; |
| 1198 | } |
| 1199 | #endif |
| 1200 | #if ENABLE_FEATURE_FIND_INUM |
| 1201 | else if (parm == PARM_inum) { |
| 1202 | action_inum *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1203 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1204 | ap = ALLOC_ACTION(inum); |
| 1205 | ap->inode_num = xatoul(arg1); |
| 1206 | } |
| 1207 | #endif |
| 1208 | #if ENABLE_FEATURE_FIND_USER |
| 1209 | else if (parm == PARM_user) { |
| 1210 | action_user *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1211 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1212 | ap = ALLOC_ACTION(user); |
| 1213 | ap->uid = bb_strtou(arg1, NULL, 10); |
| 1214 | if (errno) |
| 1215 | ap->uid = xuname2uid(arg1); |
| 1216 | } |
| 1217 | #endif |
| 1218 | #if ENABLE_FEATURE_FIND_GROUP |
| 1219 | else if (parm == PARM_group) { |
| 1220 | action_group *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1221 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1222 | ap = ALLOC_ACTION(group); |
| 1223 | ap->gid = bb_strtou(arg1, NULL, 10); |
| 1224 | if (errno) |
| 1225 | ap->gid = xgroup2gid(arg1); |
| 1226 | } |
| 1227 | #endif |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 1228 | #if ENABLE_FEATURE_FIND_SIZE |
| 1229 | else if (parm == PARM_size) { |
Denis Vlasenko | 53a0e97 | 2007-06-16 00:30:52 +0000 | [diff] [blame] | 1230 | /* -size n[bckw]: file uses n units of space |
| 1231 | * b (default): units are 512-byte blocks |
| 1232 | * c: 1 byte |
| 1233 | * k: kilobytes |
| 1234 | * w: 2-byte words |
| 1235 | */ |
| 1236 | #if ENABLE_LFS |
| 1237 | #define XATOU_SFX xatoull_sfx |
| 1238 | #else |
| 1239 | #define XATOU_SFX xatoul_sfx |
| 1240 | #endif |
| 1241 | static const struct suffix_mult find_suffixes[] = { |
Denis Vlasenko | 99fcc62 | 2007-07-01 17:29:44 +0000 | [diff] [blame] | 1242 | { "c", 1 }, |
| 1243 | { "w", 2 }, |
Denis Vlasenko | f868963 | 2007-07-27 15:06:25 +0000 | [diff] [blame] | 1244 | { "", 512 }, |
Denis Vlasenko | 99fcc62 | 2007-07-01 17:29:44 +0000 | [diff] [blame] | 1245 | { "b", 512 }, |
| 1246 | { "k", 1024 }, |
Denys Vlasenko | 043b1e5 | 2009-09-06 12:47:55 +0200 | [diff] [blame] | 1247 | { "", 0 } |
Denis Vlasenko | 53a0e97 | 2007-06-16 00:30:52 +0000 | [diff] [blame] | 1248 | }; |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 1249 | action_size *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1250 | dbg("%d", __LINE__); |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 1251 | ap = ALLOC_ACTION(size); |
Denis Vlasenko | 53a0e97 | 2007-06-16 00:30:52 +0000 | [diff] [blame] | 1252 | ap->size_char = arg1[0]; |
| 1253 | ap->size = XATOU_SFX(plus_minus_num(arg1), find_suffixes); |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 1254 | } |
| 1255 | #endif |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1256 | #if ENABLE_FEATURE_FIND_CONTEXT |
| 1257 | else if (parm == PARM_context) { |
| 1258 | action_context *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1259 | dbg("%d", __LINE__); |
Denis Vlasenko | a19faf8 | 2007-06-19 22:22:57 +0000 | [diff] [blame] | 1260 | ap = ALLOC_ACTION(context); |
Denys Vlasenko | a61ff51 | 2010-08-31 19:17:42 +0200 | [diff] [blame] | 1261 | /*ap->context = NULL; - ALLOC_ACTION did it */ |
Denis Vlasenko | 838daca | 2007-08-16 10:41:24 +0000 | [diff] [blame] | 1262 | /* SELinux headers erroneously declare non-const parameter */ |
| 1263 | if (selinux_raw_to_trans_context((char*)arg1, &ap->context)) |
Denis Vlasenko | 0c97c9d | 2007-10-01 11:58:38 +0000 | [diff] [blame] | 1264 | bb_simple_perror_msg(arg1); |
Denis Vlasenko | 62f0479 | 2007-04-13 10:00:12 +0000 | [diff] [blame] | 1265 | } |
| 1266 | #endif |
Matheus Izvekov | d0f601f | 2010-01-06 09:19:04 +0100 | [diff] [blame] | 1267 | #if ENABLE_FEATURE_FIND_LINKS |
| 1268 | else if (parm == PARM_links) { |
| 1269 | action_links *ap; |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1270 | dbg("%d", __LINE__); |
Matheus Izvekov | d0f601f | 2010-01-06 09:19:04 +0100 | [diff] [blame] | 1271 | ap = ALLOC_ACTION(links); |
| 1272 | ap->links_char = arg1[0]; |
| 1273 | ap->links_count = xatoul(plus_minus_num(arg1)); |
| 1274 | } |
| 1275 | #endif |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 1276 | else { |
| 1277 | bb_error_msg("unrecognized: %s", arg); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1278 | bb_show_usage(); |
Denis Vlasenko | b941129 | 2007-06-15 23:43:11 +0000 | [diff] [blame] | 1279 | } |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1280 | argv++; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1281 | } |
Denys Vlasenko | 87249fb | 2011-08-11 02:27:13 +0200 | [diff] [blame] | 1282 | dbg("exiting %s", __func__); |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1283 | return appp; |
| 1284 | #undef ALLOC_ACTION |
Denys Vlasenko | 6db5f67 | 2013-05-16 18:36:42 +0200 | [diff] [blame] | 1285 | #undef appp |
| 1286 | #undef cur_action |
| 1287 | #undef invert_flag |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 1290 | int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | 2ec91ae | 2010-01-04 14:15:38 +0100 | [diff] [blame] | 1291 | int find_main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1292 | { |
Denis Vlasenko | 7d6c929 | 2007-04-05 00:35:43 +0000 | [diff] [blame] | 1293 | int i, firstopt, status = EXIT_SUCCESS; |
| 1294 | |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 1295 | INIT_G(); |
| 1296 | |
Denys Vlasenko | 6782f48 | 2013-05-14 17:20:35 +0200 | [diff] [blame] | 1297 | /* "+": stop on first non-option */ |
| 1298 | i = getopt32(argv, "+HLP"); |
| 1299 | if (i & (1<<0)) |
| 1300 | G.recurse_flags |= ACTION_FOLLOWLINKS_L0 | ACTION_DANGLING_OK; |
| 1301 | if (i & (1<<1)) |
| 1302 | G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK; |
| 1303 | /* -P is default and is ignored */ |
| 1304 | argv += optind; |
| 1305 | |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1306 | for (firstopt = 0; argv[firstopt]; firstopt++) { |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1307 | if (argv[firstopt][0] == '-') |
| 1308 | break; |
Denis Vlasenko | cf787cf | 2007-02-04 17:11:25 +0000 | [diff] [blame] | 1309 | if (ENABLE_FEATURE_FIND_NOT && LONE_CHAR(argv[firstopt], '!')) |
| 1310 | break; |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1311 | if (ENABLE_FEATURE_FIND_PAREN && LONE_CHAR(argv[firstopt], '(')) |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1312 | break; |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1313 | } |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1314 | if (firstopt == 0) { |
| 1315 | *--argv = (char*)"."; |
Denis Vlasenko | 6191a7a | 2006-10-30 02:10:47 +0000 | [diff] [blame] | 1316 | firstopt++; |
| 1317 | } |
| 1318 | |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 1319 | G.actions = parse_params(&argv[firstopt]); |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1320 | argv[firstopt] = NULL; |
Denis Vlasenko | 5d499e1 | 2006-10-29 19:07:01 +0000 | [diff] [blame] | 1321 | |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1322 | #if ENABLE_FEATURE_FIND_XDEV |
| 1323 | if (G.xdev_on) { |
| 1324 | struct stat stbuf; |
| 1325 | |
| 1326 | G.xdev_count = firstopt; |
| 1327 | G.xdev_dev = xzalloc(G.xdev_count * sizeof(G.xdev_dev[0])); |
| 1328 | for (i = 0; argv[i]; i++) { |
| 1329 | /* not xstat(): shouldn't bomb out on |
| 1330 | * "find not_exist exist -xdev" */ |
| 1331 | if (stat(argv[i], &stbuf) == 0) |
| 1332 | G.xdev_dev[i] = stbuf.st_dev; |
| 1333 | /* else G.xdev_dev[i] stays 0 and |
| 1334 | * won't match any real device dev_t |
| 1335 | */ |
| 1336 | } |
| 1337 | } |
| 1338 | #endif |
| 1339 | |
| 1340 | for (i = 0; argv[i]; i++) { |
Denis Vlasenko | e2fb719 | 2006-10-29 19:03:56 +0000 | [diff] [blame] | 1341 | if (!recursive_action(argv[i], |
Denys Vlasenko | 8f7a6d2 | 2009-09-29 11:07:04 +0200 | [diff] [blame] | 1342 | G.recurse_flags,/* flags */ |
Bernhard Reutner-Fischer | 3e816c1 | 2007-03-29 10:30:50 +0000 | [diff] [blame] | 1343 | fileAction, /* file action */ |
| 1344 | fileAction, /* dir action */ |
| 1345 | NULL, /* user data */ |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1346 | 0) /* depth */ |
| 1347 | ) { |
Denis Vlasenko | e2fb719 | 2006-10-29 19:03:56 +0000 | [diff] [blame] | 1348 | status = EXIT_FAILURE; |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1349 | } |
Denis Vlasenko | e2fb719 | 2006-10-29 19:03:56 +0000 | [diff] [blame] | 1350 | } |
Denys Vlasenko | 053c12e | 2011-02-12 20:27:13 +0100 | [diff] [blame] | 1351 | |
Matt Kraai | 096370d | 2001-02-07 03:52:38 +0000 | [diff] [blame] | 1352 | return status; |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 1353 | } |