find: cater for libc w/o FNM_CASEFOLD
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 22 May 2011 22:40:54 +0000 (00:40 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 22 May 2011 22:40:54 +0000 (00:40 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
findutils/find.c
libbb/Kbuild.src
libbb/bb_basename.c [deleted file]
libbb/get_last_path_component.c

index 7918240f439c9e80bcecd3e65934730e417f4905..050d6373eb3decd98328ac935ff6aa0d7cc85500 100644 (file)
 #include <fnmatch.h>
 #include "libbb.h"
 #if ENABLE_FEATURE_FIND_REGEX
-#include "xregex.h"
+# include "xregex.h"
+#endif
+/* GNUism: */
+#ifndef FNM_CASEFOLD
+# define FNM_CASEFOLD 0
 #endif
 
 /* This is a NOEXEC applet. Be very careful! */
@@ -474,6 +478,22 @@ static int exec_actions(action ***appp, const char *fileName, const struct stat
 }
 
 
+#if !FNM_CASEFOLD
+static char *strcpy_upcase(char *dst, const char *src)
+{
+       char *d = dst;
+       while (1) {
+               unsigned char ch = *src++;
+               if (ch >= 'a' && ch <= 'z')
+                       ch -= ('a' - 'A');
+               *d++ = ch;
+               if (ch == '\0')
+                       break;
+       }
+       return dst;
+}
+#endif
+
 ACTF(name)
 {
        const char *tmp = bb_basename(fileName);
@@ -489,13 +509,25 @@ ACTF(name)
         * but somewhere between 4.1.20 and 4.4.0 GNU find stopped using it.
         * find -name '*foo' should match .foo too:
         */
+#if FNM_CASEFOLD
        return fnmatch(ap->pattern, tmp, (ap->iname ? FNM_CASEFOLD : 0)) == 0;
+#else
+       if (ap->iname)
+               tmp = strcpy_upcase(alloca(strlen(tmp) + 1), tmp);
+       return fnmatch(ap->pattern, tmp, 0) == 0;
+#endif
 }
 
 #if ENABLE_FEATURE_FIND_PATH
 ACTF(path)
 {
+# if FNM_CASEFOLD
        return fnmatch(ap->pattern, fileName, (ap->ipath ? FNM_CASEFOLD : 0)) == 0;
+# else
+       if (ap->ipath)
+               fileName = strcpy_upcase(alloca(strlen(fileName) + 1), fileName);
+       return fnmatch(ap->pattern, fileName, 0) == 0;
+# endif
 }
 #endif
 #if ENABLE_FEATURE_FIND_REGEX
index a22e7089286d6ed27c4832cad2c2402b9aff57ce..fa6e5b6e349cddfda8b4955b3490394fea34c741 100644 (file)
@@ -13,7 +13,6 @@ INSERT
 lib-y += appletlib.o
 lib-y += ask_confirmation.o
 lib-y += bb_askpass.o
-lib-y += bb_basename.o
 lib-y += bb_bswap_64.o
 lib-y += bb_do_delay.o
 lib-y += bb_pwd.o
diff --git a/libbb/bb_basename.c b/libbb/bb_basename.c
deleted file mode 100644 (file)
index d678360..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 2007 Denys Vlasenko
- *
- * Licensed under GPLv2, see file LICENSE in this source tree.
- */
-
-#include "libbb.h"
-
-const char* FAST_FUNC bb_basename(const char *name)
-{
-       const char *cp = strrchr(name, '/');
-       if (cp)
-               return cp + 1;
-       return name;
-}
index 72598d22e6bd37780aeb948a5822556420ffa790..04fdf2a3e5700bc24184ed2fc0e9e47962988712 100644 (file)
@@ -6,8 +6,16 @@
  *
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
-
 #include "libbb.h"
+
+const char* FAST_FUNC bb_basename(const char *name)
+{
+       const char *cp = strrchr(name, '/');
+       if (cp)
+               return cp + 1;
+       return name;
+}
+
 /*
  * "/"        -> "/"
  * "abc"      -> "abc"