aboutsummaryrefslogtreecommitdiff
path: root/findutils/find.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-05-23 00:40:54 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-05-23 00:40:54 +0200
commitb24ef035bd08919075edd79b906e18909ac44eb9 (patch)
tree78485aace67fbbf061b339b81af143b074ee4108 /findutils/find.c
parent7948ecb505135c811a44bc8f8e391622d893d383 (diff)
downloadbusybox-w32-b24ef035bd08919075edd79b906e18909ac44eb9.tar.gz
busybox-w32-b24ef035bd08919075edd79b906e18909ac44eb9.tar.bz2
busybox-w32-b24ef035bd08919075edd79b906e18909ac44eb9.zip
find: cater for libc w/o FNM_CASEFOLD
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'findutils/find.c')
-rw-r--r--findutils/find.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 7918240f4..050d6373e 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -330,7 +330,11 @@
330#include <fnmatch.h> 330#include <fnmatch.h>
331#include "libbb.h" 331#include "libbb.h"
332#if ENABLE_FEATURE_FIND_REGEX 332#if ENABLE_FEATURE_FIND_REGEX
333#include "xregex.h" 333# include "xregex.h"
334#endif
335/* GNUism: */
336#ifndef FNM_CASEFOLD
337# define FNM_CASEFOLD 0
334#endif 338#endif
335 339
336/* This is a NOEXEC applet. Be very careful! */ 340/* This is a NOEXEC applet. Be very careful! */
@@ -474,6 +478,22 @@ static int exec_actions(action ***appp, const char *fileName, const struct stat
474} 478}
475 479
476 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
477ACTF(name) 497ACTF(name)
478{ 498{
479 const char *tmp = bb_basename(fileName); 499 const char *tmp = bb_basename(fileName);
@@ -489,13 +509,25 @@ ACTF(name)
489 * 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.
490 * find -name '*foo' should match .foo too: 510 * find -name '*foo' should match .foo too:
491 */ 511 */
512#if FNM_CASEFOLD
492 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
493} 519}
494 520
495#if ENABLE_FEATURE_FIND_PATH 521#if ENABLE_FEATURE_FIND_PATH
496ACTF(path) 522ACTF(path)
497{ 523{
524# if FNM_CASEFOLD
498 return fnmatch(ap->pattern, fileName, (ap->ipath ? FNM_CASEFOLD : 0)) == 0; 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);
529 return fnmatch(ap->pattern, fileName, 0) == 0;
530# endif
499} 531}
500#endif 532#endif
501#if ENABLE_FEATURE_FIND_REGEX 533#if ENABLE_FEATURE_FIND_REGEX