From 008e73b5728b19c7ba6e746e279c4bc8a1935f0d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Jul 2018 21:04:41 +0200 Subject: find: implement -executable function old new delta func_executable - 19 +19 parse_params 1505 1519 +14 static.params 216 228 +12 packed_usage 32847 32855 +8 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/0 up/down: 53/0) Total: 53 bytes Signed-off-by: Denys Vlasenko --- findutils/find.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'findutils/find.c') diff --git a/findutils/find.c b/findutils/find.c index 72732615b..6407c6c5a 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -95,6 +95,11 @@ //config: Enable searching based on file type (file, //config: directory, socket, device, etc.). //config: +//config:config FEATURE_FIND_EXECUTABLE +//config: bool "Enable -executable: file is executable" +//config: default y +//config: depends on FIND +//config: //config:config FEATURE_FIND_XDEV //config: bool "Enable -xdev: 'stay in filesystem'" //config: default y @@ -272,6 +277,9 @@ //usage: IF_FEATURE_FIND_TYPE( //usage: "\n -type X File type is X (one of: f,d,l,b,c,s,p)" //usage: ) +//usage: IF_FEATURE_FIND_EXECUTABLE( +//usage: "\n -executable File is executable" +//usage: ) //usage: IF_FEATURE_FIND_PERM( //usage: "\n -perm MASK At least one mask bit (+MASK), all bits (-MASK)," //usage: "\n or exactly MASK bits are set in file's mode" @@ -375,6 +383,7 @@ IF_FEATURE_FIND_PATH( ACTS(path, const char *pattern; bool ipath;)) IF_FEATURE_FIND_REGEX( ACTS(regex, regex_t compiled_pattern;)) IF_FEATURE_FIND_PRINT0( ACTS(print0)) IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;)) +IF_FEATURE_FIND_EXECUTABLE(ACTS(executable)) IF_FEATURE_FIND_PERM( ACTS(perm, char perm_char; mode_t perm_mask;)) IF_FEATURE_FIND_MTIME( ACTS(mtime, char mtime_char; unsigned mtime_days;)) IF_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; unsigned mmin_mins;)) @@ -578,6 +587,12 @@ ACTF(type) return ((statbuf->st_mode & S_IFMT) == ap->type_mask); } #endif +#if ENABLE_FEATURE_FIND_EXECUTABLE +ACTF(executable) +{ + return access(fileName, X_OK) == 0; +} +#endif #if ENABLE_FEATURE_FIND_PERM ACTF(perm) { @@ -975,6 +990,7 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_QUIT( PARM_quit ,) IF_FEATURE_FIND_DELETE( PARM_delete ,) IF_FEATURE_FIND_EXEC( PARM_exec ,) + IF_FEATURE_FIND_EXECUTABLE(PARM_executable,) IF_FEATURE_FIND_PAREN( PARM_char_brace,) /* All options/actions starting from here require argument */ PARM_name , @@ -1019,6 +1035,7 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_QUIT( "-quit\0" ) IF_FEATURE_FIND_DELETE( "-delete\0" ) IF_FEATURE_FIND_EXEC( "-exec\0" ) + IF_FEATURE_FIND_EXECUTABLE("-executable\0") IF_FEATURE_FIND_PAREN( "(\0" ) /* All options/actions starting from here require argument */ "-name\0" @@ -1288,6 +1305,11 @@ static action*** parse_params(char **argv) dbg("created:type mask:%x", ap->type_mask); } #endif +#if ENABLE_FEATURE_FIND_EXECUTABLE + else if (parm == PARM_executable) { + (void) ALLOC_ACTION(executable); + } +#endif #if ENABLE_FEATURE_FIND_PERM /* -perm BITS File's mode bits are exactly BITS (octal or symbolic). * Symbolic modes use mode 0 as a point of departure. -- cgit v1.2.3