diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-05-23 00:40:54 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-05-23 00:40:54 +0200 |
commit | b24ef035bd08919075edd79b906e18909ac44eb9 (patch) | |
tree | 78485aace67fbbf061b339b81af143b074ee4108 | |
parent | 7948ecb505135c811a44bc8f8e391622d893d383 (diff) | |
download | busybox-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>
-rw-r--r-- | findutils/find.c | 34 | ||||
-rw-r--r-- | libbb/Kbuild.src | 1 | ||||
-rw-r--r-- | libbb/bb_basename.c | 18 | ||||
-rw-r--r-- | libbb/get_last_path_component.c | 10 |
4 files changed, 42 insertions, 21 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 | ||
482 | static 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 | |||
477 | ACTF(name) | 497 | ACTF(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 |
496 | ACTF(path) | 522 | ACTF(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 |
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index a22e70892..fa6e5b6e3 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src | |||
@@ -13,7 +13,6 @@ INSERT | |||
13 | lib-y += appletlib.o | 13 | lib-y += appletlib.o |
14 | lib-y += ask_confirmation.o | 14 | lib-y += ask_confirmation.o |
15 | lib-y += bb_askpass.o | 15 | lib-y += bb_askpass.o |
16 | lib-y += bb_basename.o | ||
17 | lib-y += bb_bswap_64.o | 16 | lib-y += bb_bswap_64.o |
18 | lib-y += bb_do_delay.o | 17 | lib-y += bb_do_delay.o |
19 | lib-y += bb_pwd.o | 18 | lib-y += bb_pwd.o |
diff --git a/libbb/bb_basename.c b/libbb/bb_basename.c deleted file mode 100644 index d678360fc..000000000 --- a/libbb/bb_basename.c +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Utility routines. | ||
4 | * | ||
5 | * Copyright (C) 2007 Denys Vlasenko | ||
6 | * | ||
7 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
8 | */ | ||
9 | |||
10 | #include "libbb.h" | ||
11 | |||
12 | const char* FAST_FUNC bb_basename(const char *name) | ||
13 | { | ||
14 | const char *cp = strrchr(name, '/'); | ||
15 | if (cp) | ||
16 | return cp + 1; | ||
17 | return name; | ||
18 | } | ||
diff --git a/libbb/get_last_path_component.c b/libbb/get_last_path_component.c index 72598d22e..04fdf2a3e 100644 --- a/libbb/get_last_path_component.c +++ b/libbb/get_last_path_component.c | |||
@@ -6,8 +6,16 @@ | |||
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
8 | */ | 8 | */ |
9 | |||
10 | #include "libbb.h" | 9 | #include "libbb.h" |
10 | |||
11 | const char* FAST_FUNC bb_basename(const char *name) | ||
12 | { | ||
13 | const char *cp = strrchr(name, '/'); | ||
14 | if (cp) | ||
15 | return cp + 1; | ||
16 | return name; | ||
17 | } | ||
18 | |||
11 | /* | 19 | /* |
12 | * "/" -> "/" | 20 | * "/" -> "/" |
13 | * "abc" -> "abc" | 21 | * "abc" -> "abc" |