aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-22 15:21:20 +0000
committerRon Yorston <rmy@pobox.com>2012-03-22 15:21:20 +0000
commit0d8b2c4a929ea9d3ac37499319fe0d8e7941a0c2 (patch)
tree6709ddd6071a9c238ba69233540bbcfe560c6a44 /findutils
parent67758035a4fe040c6ac69b39d61bcd6bddd7b827 (diff)
parent56a3b82e9692a25ef9c9269e88feac0d579ce8e8 (diff)
downloadbusybox-w32-0d8b2c4a929ea9d3ac37499319fe0d8e7941a0c2.tar.gz
busybox-w32-0d8b2c4a929ea9d3ac37499319fe0d8e7941a0c2.tar.bz2
busybox-w32-0d8b2c4a929ea9d3ac37499319fe0d8e7941a0c2.zip
Merge commit '56a3b82e9692a25ef9c9269e88feac0d579ce8e8' into merge
Conflicts: coreutils/ls.c include/platform.h libbb/bb_basename.c
Diffstat (limited to 'findutils')
-rw-r--r--findutils/find.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 9ae84fa0d..050d6373e 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -264,6 +264,7 @@
264//usage: "\n -iname PATTERN Case insensitive -name" 264//usage: "\n -iname PATTERN Case insensitive -name"
265//usage: IF_FEATURE_FIND_PATH( 265//usage: IF_FEATURE_FIND_PATH(
266//usage: "\n -path PATTERN Match path to PATTERN" 266//usage: "\n -path PATTERN Match path to PATTERN"
267//usage: "\n -ipath PATTERN Case insensitive -path"
267//usage: ) 268//usage: )
268//usage: IF_FEATURE_FIND_REGEX( 269//usage: IF_FEATURE_FIND_REGEX(
269//usage: "\n -regex PATTERN Match path to regex PATTERN" 270//usage: "\n -regex PATTERN Match path to regex PATTERN"
@@ -329,7 +330,11 @@
329#include <fnmatch.h> 330#include <fnmatch.h>
330#include "libbb.h" 331#include "libbb.h"
331#if ENABLE_FEATURE_FIND_REGEX 332#if ENABLE_FEATURE_FIND_REGEX
332#include "xregex.h" 333# include "xregex.h"
334#endif
335/* GNUism: */
336#ifndef FNM_CASEFOLD
337# define FNM_CASEFOLD 0
333#endif 338#endif
334 339
335/* This is a NOEXEC applet. Be very careful! */ 340/* This is a NOEXEC applet. Be very careful! */
@@ -352,7 +357,7 @@ typedef struct {
352 357
353 ACTS(print) 358 ACTS(print)
354 ACTS(name, const char *pattern; bool iname;) 359 ACTS(name, const char *pattern; bool iname;)
355IF_FEATURE_FIND_PATH( ACTS(path, const char *pattern;)) 360IF_FEATURE_FIND_PATH( ACTS(path, const char *pattern; bool ipath;))
356IF_FEATURE_FIND_REGEX( ACTS(regex, regex_t compiled_pattern;)) 361IF_FEATURE_FIND_REGEX( ACTS(regex, regex_t compiled_pattern;))
357IF_FEATURE_FIND_PRINT0( ACTS(print0)) 362IF_FEATURE_FIND_PRINT0( ACTS(print0))
358IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;)) 363IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;))
@@ -473,6 +478,22 @@ static int exec_actions(action ***appp, const char *fileName, const struct stat
473} 478}
474 479
475 480
481#if !FNM_CASEFOLD
482static char *strcpy_upcase(char *dst, const char *src)
483{
484 char *d = dst;
485 while (1) {
486 unsigned char ch = *src++;
487 if (ch >= 'a' && ch <= 'z')
488 ch -= ('a' - 'A');
489 *d++ = ch;
490 if (ch == '\0')
491 break;
492 }
493 return dst;
494}
495#endif
496
476ACTF(name) 497ACTF(name)
477{ 498{
478 const char *tmp = bb_basename(fileName); 499 const char *tmp = bb_basename(fileName);
@@ -488,13 +509,25 @@ ACTF(name)
488 * but somewhere between 4.1.20 and 4.4.0 GNU find stopped using it. 509 * but somewhere between 4.1.20 and 4.4.0 GNU find stopped using it.
489 * find -name '*foo' should match .foo too: 510 * find -name '*foo' should match .foo too:
490 */ 511 */
512#if FNM_CASEFOLD
491 return fnmatch(ap->pattern, tmp, (ap->iname ? FNM_CASEFOLD : 0)) == 0; 513 return fnmatch(ap->pattern, tmp, (ap->iname ? FNM_CASEFOLD : 0)) == 0;
514#else
515 if (ap->iname)
516 tmp = strcpy_upcase(alloca(strlen(tmp) + 1), tmp);
517 return fnmatch(ap->pattern, tmp, 0) == 0;
518#endif
492} 519}
493 520
494#if ENABLE_FEATURE_FIND_PATH 521#if ENABLE_FEATURE_FIND_PATH
495ACTF(path) 522ACTF(path)
496{ 523{
524# if FNM_CASEFOLD
525 return fnmatch(ap->pattern, fileName, (ap->ipath ? FNM_CASEFOLD : 0)) == 0;
526# else
527 if (ap->ipath)
528 fileName = strcpy_upcase(alloca(strlen(fileName) + 1), fileName);
497 return fnmatch(ap->pattern, fileName, 0) == 0; 529 return fnmatch(ap->pattern, fileName, 0) == 0;
530# endif
498} 531}
499#endif 532#endif
500#if ENABLE_FEATURE_FIND_REGEX 533#if ENABLE_FEATURE_FIND_REGEX
@@ -794,6 +827,7 @@ static action*** parse_params(char **argv)
794 PARM_name , 827 PARM_name ,
795 PARM_iname , 828 PARM_iname ,
796 IF_FEATURE_FIND_PATH( PARM_path ,) 829 IF_FEATURE_FIND_PATH( PARM_path ,)
830 IF_FEATURE_FIND_PATH( PARM_ipath ,)
797 IF_FEATURE_FIND_REGEX( PARM_regex ,) 831 IF_FEATURE_FIND_REGEX( PARM_regex ,)
798 IF_FEATURE_FIND_TYPE( PARM_type ,) 832 IF_FEATURE_FIND_TYPE( PARM_type ,)
799 IF_FEATURE_FIND_PERM( PARM_perm ,) 833 IF_FEATURE_FIND_PERM( PARM_perm ,)
@@ -831,6 +865,7 @@ static action*** parse_params(char **argv)
831 "-name\0" 865 "-name\0"
832 "-iname\0" 866 "-iname\0"
833 IF_FEATURE_FIND_PATH( "-path\0" ) 867 IF_FEATURE_FIND_PATH( "-path\0" )
868 IF_FEATURE_FIND_PATH( "-ipath\0" )
834 IF_FEATURE_FIND_REGEX( "-regex\0" ) 869 IF_FEATURE_FIND_REGEX( "-regex\0" )
835 IF_FEATURE_FIND_TYPE( "-type\0" ) 870 IF_FEATURE_FIND_TYPE( "-type\0" )
836 IF_FEATURE_FIND_PERM( "-perm\0" ) 871 IF_FEATURE_FIND_PERM( "-perm\0" )
@@ -1018,10 +1053,11 @@ static action*** parse_params(char **argv)
1018 ap->iname = (parm == PARM_iname); 1053 ap->iname = (parm == PARM_iname);
1019 } 1054 }
1020#if ENABLE_FEATURE_FIND_PATH 1055#if ENABLE_FEATURE_FIND_PATH
1021 else if (parm == PARM_path) { 1056 else if (parm == PARM_path || parm == PARM_ipath) {
1022 action_path *ap; 1057 action_path *ap;
1023 ap = ALLOC_ACTION(path); 1058 ap = ALLOC_ACTION(path);
1024 ap->pattern = arg1; 1059 ap->pattern = arg1;
1060 ap->ipath = (parm == PARM_ipath);
1025 } 1061 }
1026#endif 1062#endif
1027#if ENABLE_FEATURE_FIND_REGEX 1063#if ENABLE_FEATURE_FIND_REGEX