#endif
} action;
#define ACTS(name, arg...) typedef struct { action a; arg; } action_##name;
-#define ACTF(name) static int func_##name(const char *fileName, struct stat *statbuf, action_##name* ap)
+#define ACTF(name) static int func_##name(const char *fileName ATTRIBUTE_UNUSED, \
+ struct stat *statbuf ATTRIBUTE_UNUSED, \
+ action_##name* ap ATTRIBUTE_UNUSED)
ACTS(print)
- ACTS(name, const char *pattern;)
+ ACTS(name, const char *pattern; bool iname;)
USE_FEATURE_FIND_PATH( ACTS(path, const char *pattern;))
USE_FEATURE_FIND_REGEX( ACTS(regex, regex_t compiled_pattern;))
USE_FEATURE_FIND_PRINT0( ACTS(print0))
if (*tmp == '/')
tmp++;
}
- return fnmatch(ap->pattern, tmp, FNM_PERIOD) == 0;
+ return fnmatch(ap->pattern, tmp, FNM_PERIOD | (ap->iname ? FNM_CASEFOLD : 0)) == 0;
}
+
#if ENABLE_FEATURE_FIND_PATH
ACTF(path)
{
rc = spawn_and_wait(argv);
if (rc < 0)
- bb_perror_msg("%s", argv[0]);
+ bb_simple_perror_msg(argv[0]);
i = 0;
while (argv[i])
rc = unlink(fileName);
}
if (rc < 0)
- bb_perror_msg("%s", fileName);
+ bb_simple_perror_msg(fileName);
return TRUE;
}
#endif
#if ENABLE_FEATURE_FIND_XDEV
if (S_ISDIR(statbuf->st_mode) && xdev_count) {
for (i = 0; i < xdev_count; i++) {
- if (xdev_dev[i] != statbuf->st_dev)
- return SKIP;
+ if (xdev_dev[i] == statbuf->st_dev)
+ break;
}
+ if (i == xdev_count)
+ return SKIP;
}
#endif
i = exec_actions(actions, fileName, statbuf);
}
#endif
-#if ENABLE_FEATURE_FIND_PERM || ENABLE_FEATURE_FIND_MTIME \
- || ENABLE_FEATURE_FIND_MMIN
+#if ENABLE_FEATURE_FIND_PERM \
+ || ENABLE_FEATURE_FIND_MTIME || ENABLE_FEATURE_FIND_MMIN \
+ || ENABLE_FEATURE_FIND_SIZE
static const char* plus_minus_num(const char* str)
{
if (*str == '-' || *str == '+')
USE_FEATURE_FIND_PAREN( PARM_char_brace,)
/* All options starting from here require argument */
PARM_name ,
+ PARM_iname ,
USE_FEATURE_FIND_PATH( PARM_path ,)
USE_FEATURE_FIND_REGEX( PARM_regex ,)
USE_FEATURE_FIND_TYPE( PARM_type ,)
USE_FEATURE_FIND_CONTEXT(PARM_context ,)
};
- static const char *const params[] = {
- "-a" ,
- "-o" ,
- USE_FEATURE_FIND_NOT( "!" ,)
+ static const char params[] ALIGN1 =
+ "-a\0"
+ "-o\0"
+ USE_FEATURE_FIND_NOT( "!\0" )
#if ENABLE_DESKTOP
- "-and" ,
- "-or" ,
- USE_FEATURE_FIND_NOT( "-not" ,)
-#endif
- "-print" ,
- USE_FEATURE_FIND_PRINT0( "-print0" ,)
- USE_FEATURE_FIND_DEPTH( "-depth" ,)
- USE_FEATURE_FIND_PRUNE( "-prune" ,)
- USE_FEATURE_FIND_DELETE( "-delete" ,)
- USE_FEATURE_FIND_EXEC( "-exec" ,)
- USE_FEATURE_FIND_PAREN( "(" ,)
+ "-and\0"
+ "-or\0"
+ USE_FEATURE_FIND_NOT( "-not\0" )
+#endif
+ "-print\0"
+ USE_FEATURE_FIND_PRINT0( "-print0\0" )
+ USE_FEATURE_FIND_DEPTH( "-depth\0" )
+ USE_FEATURE_FIND_PRUNE( "-prune\0" )
+ USE_FEATURE_FIND_DELETE( "-delete\0" )
+ USE_FEATURE_FIND_EXEC( "-exec\0" )
+ USE_FEATURE_FIND_PAREN( "(\0" )
/* All options starting from here require argument */
- "-name" ,
- USE_FEATURE_FIND_PATH( "-path" ,)
- USE_FEATURE_FIND_REGEX( "-regex" ,)
- USE_FEATURE_FIND_TYPE( "-type" ,)
- USE_FEATURE_FIND_PERM( "-perm" ,)
- USE_FEATURE_FIND_MTIME( "-mtime" ,)
- USE_FEATURE_FIND_MMIN( "-mmin" ,)
- USE_FEATURE_FIND_NEWER( "-newer" ,)
- USE_FEATURE_FIND_INUM( "-inum" ,)
- USE_FEATURE_FIND_USER( "-user" ,)
- USE_FEATURE_FIND_GROUP( "-group" ,)
- USE_FEATURE_FIND_SIZE( "-size" ,)
- USE_FEATURE_FIND_CONTEXT("-context",)
- NULL
- };
+ "-name\0"
+ "-iname\0"
+ USE_FEATURE_FIND_PATH( "-path\0" )
+ USE_FEATURE_FIND_REGEX( "-regex\0" )
+ USE_FEATURE_FIND_TYPE( "-type\0" )
+ USE_FEATURE_FIND_PERM( "-perm\0" )
+ USE_FEATURE_FIND_MTIME( "-mtime\0" )
+ USE_FEATURE_FIND_MMIN( "-mmin\0" )
+ USE_FEATURE_FIND_NEWER( "-newer\0" )
+ USE_FEATURE_FIND_INUM( "-inum\0" )
+ USE_FEATURE_FIND_USER( "-user\0" )
+ USE_FEATURE_FIND_GROUP( "-group\0" )
+ USE_FEATURE_FIND_SIZE( "-size\0" )
+ USE_FEATURE_FIND_CONTEXT("-context\0")
+ ;
action*** appp;
unsigned cur_group = 0;
*/
while (*argv) {
const char *arg = argv[0];
- int parm = index_in_str_array(params, arg);
+ int parm = index_in_strings(params, arg);
const char *arg1 = argv[1];
if (parm >= PARM_name) {
argv = endarg;
}
#endif
- else if (parm == PARM_name) {
+ else if (parm == PARM_name || parm == PARM_iname) {
action_name *ap;
ap = ALLOC_ACTION(name);
ap->pattern = arg1;
+ ap->iname = (parm == PARM_iname);
}
#if ENABLE_FEATURE_FIND_PATH
else if (parm == PARM_path) {
#define XATOU_SFX xatoul_sfx
#endif
static const struct suffix_mult find_suffixes[] = {
- { "c", 1 },
- { "w", 2 },
- { "b"+1, 512 },
- { "b", 512 },
- { "k", 1024 },
- { NULL, 0 }
+ { "c", 1 },
+ { "w", 2 },
+ { "", 512 },
+ { "b", 512 },
+ { "k", 1024 },
+ { }
};
action_size *ap;
ap = ALLOC_ACTION(size);
action_context *ap;
ap = ALLOC_ACTION(context);
ap->context = NULL;
- if (selinux_raw_to_trans_context(arg1, &ap->context))
- bb_perror_msg("%s", arg1);
+ /* SELinux headers erroneously declare non-const parameter */
+ if (selinux_raw_to_trans_context((char*)arg1, &ap->context))
+ bb_simple_perror_msg(arg1);
}
#endif
else {
}
-int find_main(int argc, char **argv);
+int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int find_main(int argc, char **argv)
{
- static const char *const options[] = {
- "-follow",
-USE_FEATURE_FIND_XDEV( "-xdev" ,)
-USE_FEATURE_FIND_MAXDEPTH("-maxdepth",)
- NULL
- };
+ static const char options[] ALIGN1 =
+ "-follow\0"
+USE_FEATURE_FIND_XDEV( "-xdev\0" )
+USE_FEATURE_FIND_MAXDEPTH("-maxdepth\0")
+ ;
enum {
- OPT_FOLLOW,
+ OPT_FOLLOW,
USE_FEATURE_FIND_XDEV( OPT_XDEV ,)
USE_FEATURE_FIND_MAXDEPTH(OPT_MAXDEPTH,)
};
/* (-a will be ignored by recursive parser later) */
argp = &argv[firstopt];
while ((arg = argp[0])) {
- int opt = index_in_str_array(options, arg);
+ int opt = index_in_strings(options, arg);
if (opt == OPT_FOLLOW) {
recurse_flags |= ACTION_FOLLOWLINKS;
argp[0] = (char*)"-a";
fileAction, /* file action */
fileAction, /* dir action */
#if ENABLE_FEATURE_FIND_MAXDEPTH
- (void*)maxdepth,/* user data */
+ /* double cast suppresses
+ * "cast to ptr from int of different size" */
+ (void*)(ptrdiff_t)maxdepth,/* user data */
#else
NULL, /* user data */
#endif