aboutsummaryrefslogtreecommitdiff
path: root/findutils/find.c
diff options
context:
space:
mode:
authorMatheus Izvekov <mizvekov@gmail.com>2010-01-06 09:19:04 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-06 09:19:04 +0100
commitd0f601f066d290d4a2dfb08ab724c6c7f4353649 (patch)
tree24659bc853cd541a5dff29e6754d1568a3d354c2 /findutils/find.c
parent839fd71077d457c9e86afc56ba5cc54a0e1fcfb8 (diff)
downloadbusybox-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>
Diffstat (limited to 'findutils/find.c')
-rw-r--r--findutils/find.c26
1 files changed, 23 insertions, 3 deletions
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))
96IF_FEATURE_FIND_DELETE( ACTS(delete)) 96IF_FEATURE_FIND_DELETE( ACTS(delete))
97IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;)) 97IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;))
98IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;)) 98IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
99IF_FEATURE_FIND_LINKS( ACTS(links, char links_char; int links_count;))
99 100
100struct globals { 101struct 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
395ACTF(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
395static int FAST_FUNC fileAction(const char *fileName, 405static 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
467static const char* plus_minus_num(const char* str) 477static 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();