diff options
author | Matheus Izvekov <mizvekov@gmail.com> | 2010-01-06 09:19:04 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-06 09:19:04 +0100 |
commit | d0f601f066d290d4a2dfb08ab724c6c7f4353649 (patch) | |
tree | 24659bc853cd541a5dff29e6754d1568a3d354c2 | |
parent | 839fd71077d457c9e86afc56ba5cc54a0e1fcfb8 (diff) | |
download | busybox-w32-d0f601f066d290d4a2dfb08ab724c6c7f4353649.tar.gz busybox-w32-d0f601f066d290d4a2dfb08ab724c6c7f4353649.tar.bz2 busybox-w32-d0f601f066d290d4a2dfb08ab724c6c7f4353649.zip |
find: add optional support for -links. +100 bytes
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | findutils/Config.in | 7 | ||||
-rw-r--r-- | findutils/find.c | 26 | ||||
-rw-r--r-- | include/usage.h | 9 |
3 files changed, 36 insertions, 6 deletions
diff --git a/findutils/Config.in b/findutils/Config.in index f274ad1c6..8582d6446 100644 --- a/findutils/Config.in +++ b/findutils/Config.in | |||
@@ -171,6 +171,13 @@ config FEATURE_FIND_CONTEXT | |||
171 | help | 171 | help |
172 | Support the 'find -context' option for matching security context. | 172 | Support the 'find -context' option for matching security context. |
173 | 173 | ||
174 | config FEATURE_FIND_LINKS | ||
175 | bool "Enable -links: link count matching" | ||
176 | default n | ||
177 | depends on FIND | ||
178 | help | ||
179 | Support the 'find -links' option for matching number of links. | ||
180 | |||
174 | config GREP | 181 | config GREP |
175 | bool "grep" | 182 | bool "grep" |
176 | default n | 183 | default n |
diff --git a/findutils/find.c b/findutils/find.c index 1b2466816..f0c259833 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -96,6 +96,7 @@ IF_FEATURE_FIND_PRUNE( ACTS(prune)) | |||
96 | IF_FEATURE_FIND_DELETE( ACTS(delete)) | 96 | IF_FEATURE_FIND_DELETE( ACTS(delete)) |
97 | IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;)) | 97 | IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;)) |
98 | IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;)) | 98 | IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;)) |
99 | IF_FEATURE_FIND_LINKS( ACTS(links, char links_char; int links_count;)) | ||
99 | 100 | ||
100 | struct globals { | 101 | struct globals { |
101 | IF_FEATURE_FIND_XDEV(dev_t *xdev_dev;) | 102 | IF_FEATURE_FIND_XDEV(dev_t *xdev_dev;) |
@@ -175,7 +176,7 @@ static int exec_actions(action ***appp, const char *fileName, const struct stat | |||
175 | * On return, bit is restored. */ | 176 | * On return, bit is restored. */ |
176 | 177 | ||
177 | cur_group = -1; | 178 | cur_group = -1; |
178 | while ((app = appp[++cur_group])) { | 179 | while ((app = appp[++cur_group]) != NULL) { |
179 | rc &= ~TRUE; /* 'success' so far, clear TRUE bit */ | 180 | rc &= ~TRUE; /* 'success' so far, clear TRUE bit */ |
180 | cur_action = -1; | 181 | cur_action = -1; |
181 | while (1) { | 182 | while (1) { |
@@ -390,7 +391,16 @@ ACTF(context) | |||
390 | return rc == 0; | 391 | return rc == 0; |
391 | } | 392 | } |
392 | #endif | 393 | #endif |
393 | 394 | #if ENABLE_FEATURE_FIND_LINKS | |
395 | ACTF(links) | ||
396 | { | ||
397 | switch(ap->links_char) { | ||
398 | case '-' : return (statbuf->st_nlink < ap->links_count); | ||
399 | case '+' : return (statbuf->st_nlink > ap->links_count); | ||
400 | default: return (statbuf->st_nlink == ap->links_count); | ||
401 | } | ||
402 | } | ||
403 | #endif | ||
394 | 404 | ||
395 | static int FAST_FUNC fileAction(const char *fileName, | 405 | static int FAST_FUNC fileAction(const char *fileName, |
396 | struct stat *statbuf, | 406 | struct stat *statbuf, |
@@ -463,7 +473,7 @@ static int find_type(const char *type) | |||
463 | 473 | ||
464 | #if ENABLE_FEATURE_FIND_PERM \ | 474 | #if ENABLE_FEATURE_FIND_PERM \ |
465 | || ENABLE_FEATURE_FIND_MTIME || ENABLE_FEATURE_FIND_MMIN \ | 475 | || ENABLE_FEATURE_FIND_MTIME || ENABLE_FEATURE_FIND_MMIN \ |
466 | || ENABLE_FEATURE_FIND_SIZE | 476 | || ENABLE_FEATURE_FIND_SIZE || ENABLE_FEATURE_FIND_LINKS |
467 | static const char* plus_minus_num(const char* str) | 477 | static const char* plus_minus_num(const char* str) |
468 | { | 478 | { |
469 | if (*str == '-' || *str == '+') | 479 | if (*str == '-' || *str == '+') |
@@ -505,6 +515,7 @@ static action*** parse_params(char **argv) | |||
505 | IF_FEATURE_FIND_GROUP( PARM_group ,) | 515 | IF_FEATURE_FIND_GROUP( PARM_group ,) |
506 | IF_FEATURE_FIND_SIZE( PARM_size ,) | 516 | IF_FEATURE_FIND_SIZE( PARM_size ,) |
507 | IF_FEATURE_FIND_CONTEXT(PARM_context ,) | 517 | IF_FEATURE_FIND_CONTEXT(PARM_context ,) |
518 | IF_FEATURE_FIND_LINKS( PARM_links ,) | ||
508 | }; | 519 | }; |
509 | 520 | ||
510 | static const char params[] ALIGN1 = | 521 | static const char params[] ALIGN1 = |
@@ -538,6 +549,7 @@ static action*** parse_params(char **argv) | |||
538 | IF_FEATURE_FIND_GROUP( "-group\0" ) | 549 | IF_FEATURE_FIND_GROUP( "-group\0" ) |
539 | IF_FEATURE_FIND_SIZE( "-size\0" ) | 550 | IF_FEATURE_FIND_SIZE( "-size\0" ) |
540 | IF_FEATURE_FIND_CONTEXT("-context\0") | 551 | IF_FEATURE_FIND_CONTEXT("-context\0") |
552 | IF_FEATURE_FIND_LINKS( "-links\0" ) | ||
541 | ; | 553 | ; |
542 | 554 | ||
543 | action*** appp; | 555 | action*** appp; |
@@ -823,6 +835,14 @@ static action*** parse_params(char **argv) | |||
823 | bb_simple_perror_msg(arg1); | 835 | bb_simple_perror_msg(arg1); |
824 | } | 836 | } |
825 | #endif | 837 | #endif |
838 | #if ENABLE_FEATURE_FIND_LINKS | ||
839 | else if (parm == PARM_links) { | ||
840 | action_links *ap; | ||
841 | ap = ALLOC_ACTION(links); | ||
842 | ap->links_char = arg1[0]; | ||
843 | ap->links_count = xatoul(plus_minus_num(arg1)); | ||
844 | } | ||
845 | #endif | ||
826 | else { | 846 | else { |
827 | bb_error_msg("unrecognized: %s", arg); | 847 | bb_error_msg("unrecognized: %s", arg); |
828 | bb_show_usage(); | 848 | bb_show_usage(); |
diff --git a/include/usage.h b/include/usage.h index eab57d8ae..4254e153c 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -1232,13 +1232,13 @@ | |||
1232 | "\n -type X File type is X (X is one of: f,d,l,b,c,...)") \ | 1232 | "\n -type X File type is X (X is one of: f,d,l,b,c,...)") \ |
1233 | IF_FEATURE_FIND_PERM( \ | 1233 | IF_FEATURE_FIND_PERM( \ |
1234 | "\n -perm NNN Permissions match any of (+NNN), all of (-NNN)," \ | 1234 | "\n -perm NNN Permissions match any of (+NNN), all of (-NNN)," \ |
1235 | "\n or exactly (NNN)") \ | 1235 | "\n or exactly NNN") \ |
1236 | IF_FEATURE_FIND_MTIME( \ | 1236 | IF_FEATURE_FIND_MTIME( \ |
1237 | "\n -mtime DAYS Modified time is greater than (+N), less than (-N)," \ | 1237 | "\n -mtime DAYS Modified time is greater than (+N), less than (-N)," \ |
1238 | "\n or exactly (N) days") \ | 1238 | "\n or exactly N days") \ |
1239 | IF_FEATURE_FIND_MMIN( \ | 1239 | IF_FEATURE_FIND_MMIN( \ |
1240 | "\n -mmin MINS Modified time is greater than (+N), less than (-N)," \ | 1240 | "\n -mmin MINS Modified time is greater than (+N), less than (-N)," \ |
1241 | "\n or exactly (N) minutes") \ | 1241 | "\n or exactly N minutes") \ |
1242 | IF_FEATURE_FIND_NEWER( \ | 1242 | IF_FEATURE_FIND_NEWER( \ |
1243 | "\n -newer FILE Modified time is more recent than FILE's") \ | 1243 | "\n -newer FILE Modified time is more recent than FILE's") \ |
1244 | IF_FEATURE_FIND_INUM( \ | 1244 | IF_FEATURE_FIND_INUM( \ |
@@ -1252,6 +1252,9 @@ | |||
1252 | IF_FEATURE_FIND_SIZE( \ | 1252 | IF_FEATURE_FIND_SIZE( \ |
1253 | "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))." \ | 1253 | "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))." \ |
1254 | "\n +/-N: file size is bigger/smaller than N") \ | 1254 | "\n +/-N: file size is bigger/smaller than N") \ |
1255 | IF_FEATURE_FIND_LINKS( \ | ||
1256 | "\n -links N Number of links is greater than (+N), less than (-N)," \ | ||
1257 | "\n or exactly N") \ | ||
1255 | "\n -print Print (default and assumed)" \ | 1258 | "\n -print Print (default and assumed)" \ |
1256 | IF_FEATURE_FIND_PRINT0( \ | 1259 | IF_FEATURE_FIND_PRINT0( \ |
1257 | "\n -print0 Delimit output with null characters rather than" \ | 1260 | "\n -print0 Delimit output with null characters rather than" \ |