diff options
author | Matheus Izvekov | 2010-01-06 09:19:04 +0100 |
---|---|---|
committer | Denys Vlasenko | 2010-01-06 09:19:04 +0100 |
commit | d0f601f066d290d4a2dfb08ab724c6c7f4353649 (patch) | |
tree | 24659bc853cd541a5dff29e6754d1568a3d354c2 /findutils | |
parent | 839fd71077d457c9e86afc56ba5cc54a0e1fcfb8 (diff) | |
download | busybox-d0f601f066d290d4a2dfb08ab724c6c7f4353649.zip busybox-d0f601f066d290d4a2dfb08ab724c6c7f4353649.tar.gz |
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')
-rw-r--r-- | findutils/Config.in | 7 | ||||
-rw-r--r-- | findutils/find.c | 26 |
2 files changed, 30 insertions, 3 deletions
diff --git a/findutils/Config.in b/findutils/Config.in index f274ad1..8582d64 100644 --- a/findutils/Config.in +++ b/findutils/Config.in @@ -171,6 +171,13 @@ config FEATURE_FIND_CONTEXT help Support the 'find -context' option for matching security context. +config FEATURE_FIND_LINKS + bool "Enable -links: link count matching" + default n + depends on FIND + help + Support the 'find -links' option for matching number of links. + config GREP bool "grep" default n diff --git a/findutils/find.c b/findutils/find.c index 1b24668..f0c2598 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -96,6 +96,7 @@ IF_FEATURE_FIND_PRUNE( ACTS(prune)) IF_FEATURE_FIND_DELETE( ACTS(delete)) IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;)) IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;)) +IF_FEATURE_FIND_LINKS( ACTS(links, char links_char; int links_count;)) struct globals { IF_FEATURE_FIND_XDEV(dev_t *xdev_dev;) @@ -175,7 +176,7 @@ static int exec_actions(action ***appp, const char *fileName, const struct stat * On return, bit is restored. */ cur_group = -1; - while ((app = appp[++cur_group])) { + while ((app = appp[++cur_group]) != NULL) { rc &= ~TRUE; /* 'success' so far, clear TRUE bit */ cur_action = -1; while (1) { @@ -390,7 +391,16 @@ ACTF(context) return rc == 0; } #endif - +#if ENABLE_FEATURE_FIND_LINKS +ACTF(links) +{ + switch(ap->links_char) { + case '-' : return (statbuf->st_nlink < ap->links_count); + case '+' : return (statbuf->st_nlink > ap->links_count); + default: return (statbuf->st_nlink == ap->links_count); + } +} +#endif static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, @@ -463,7 +473,7 @@ static int find_type(const char *type) #if ENABLE_FEATURE_FIND_PERM \ || ENABLE_FEATURE_FIND_MTIME || ENABLE_FEATURE_FIND_MMIN \ - || ENABLE_FEATURE_FIND_SIZE + || ENABLE_FEATURE_FIND_SIZE || ENABLE_FEATURE_FIND_LINKS static const char* plus_minus_num(const char* str) { if (*str == '-' || *str == '+') @@ -505,6 +515,7 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_GROUP( PARM_group ,) IF_FEATURE_FIND_SIZE( PARM_size ,) IF_FEATURE_FIND_CONTEXT(PARM_context ,) + IF_FEATURE_FIND_LINKS( PARM_links ,) }; static const char params[] ALIGN1 = @@ -538,6 +549,7 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_GROUP( "-group\0" ) IF_FEATURE_FIND_SIZE( "-size\0" ) IF_FEATURE_FIND_CONTEXT("-context\0") + IF_FEATURE_FIND_LINKS( "-links\0" ) ; action*** appp; @@ -823,6 +835,14 @@ static action*** parse_params(char **argv) bb_simple_perror_msg(arg1); } #endif +#if ENABLE_FEATURE_FIND_LINKS + else if (parm == PARM_links) { + action_links *ap; + ap = ALLOC_ACTION(links); + ap->links_char = arg1[0]; + ap->links_count = xatoul(plus_minus_num(arg1)); + } +#endif else { bb_error_msg("unrecognized: %s", arg); bb_show_usage(); |