aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-12-09 14:46:14 +0000
committerRon Yorston <rmy@pobox.com>2018-12-09 14:47:42 +0000
commit6691b2e8d230e1c85d1a31a752f9f5b6933edbb0 (patch)
treef9e1c83e5adf9c48c758a18f68ec172983e03c86
parent4a5a8422feab7d38f60d2576e32916f9cf711d29 (diff)
downloadbusybox-w32-6691b2e8d230e1c85d1a31a752f9f5b6933edbb0.tar.gz
busybox-w32-6691b2e8d230e1c85d1a31a752f9f5b6933edbb0.tar.bz2
busybox-w32-6691b2e8d230e1c85d1a31a752f9f5b6933edbb0.zip
win32: add a case-insensitive version of is_suffixed_with()
-rw-r--r--include/mingw.h1
-rw-r--r--libbb/compare_string_array.c28
-rw-r--r--win32/mingw.c3
3 files changed, 30 insertions, 2 deletions
diff --git a/include/mingw.h b/include/mingw.h
index b8c0b12b5..a1869227d 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -448,6 +448,7 @@ int kill_SIGTERM_by_handle(HANDLE process, int exit_code);
448#define find_mount_point(n, s) find_mount_point(n) 448#define find_mount_point(n, s) find_mount_point(n)
449 449
450char *is_prefixed_with_case(const char *string, const char *key) FAST_FUNC; 450char *is_prefixed_with_case(const char *string, const char *key) FAST_FUNC;
451char *is_suffixed_with_case(const char *string, const char *key) FAST_FUNC;
451void qsort_string_vector_case(char **sv, unsigned count) FAST_FUNC; 452void qsort_string_vector_case(char **sv, unsigned count) FAST_FUNC;
452 453
453/* 454/*
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
index 7ccdaef8a..856739c41 100644
--- a/libbb/compare_string_array.c
+++ b/libbb/compare_string_array.c
@@ -45,6 +45,7 @@ char* FAST_FUNC is_prefixed_with_case(const char *string, const char *key)
45 * beginning of prefix key in string. If key is an empty string return pointer 45 * beginning of prefix key in string. If key is an empty string return pointer
46 * to the end of string. 46 * to the end of string.
47 */ 47 */
48#if !ENABLE_PLATFORM_MINGW32
48char* FAST_FUNC is_suffixed_with(const char *string, const char *key) 49char* FAST_FUNC is_suffixed_with(const char *string, const char *key)
49{ 50{
50 size_t key_len = strlen(key); 51 size_t key_len = strlen(key);
@@ -59,6 +60,33 @@ char* FAST_FUNC is_suffixed_with(const char *string, const char *key)
59 60
60 return NULL; 61 return NULL;
61} 62}
63#else
64static char* FAST_FUNC is_suffixed(const char *string, const char *key,
65 int (*fn)(const char *, const char*))
66{
67 size_t key_len = strlen(key);
68 ssize_t len_diff = strlen(string) - key_len;
69
70 if (len_diff >= 0) {
71 string += len_diff;
72 if (fn(string, key) == 0) {
73 return (char*)string;
74 }
75 }
76
77 return NULL;
78}
79
80char* FAST_FUNC is_suffixed_with(const char *string, const char *key)
81{
82 return is_suffixed(string, key, strcmp);
83}
84
85char* FAST_FUNC is_suffixed_with_case(const char *string, const char *key)
86{
87 return is_suffixed(string, key, strcasecmp);
88}
89#endif
62 90
63/* returns the array index of the string */ 91/* returns the array index of the string */
64/* (index of first match is returned, or -1) */ 92/* (index of first match is returned, or -1) */
diff --git a/win32/mingw.c b/win32/mingw.c
index 10169266d..162fae45b 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -332,8 +332,7 @@ static int has_exec_format(const char *name)
332 unsigned char buf[1024]; 332 unsigned char buf[1024];
333 333
334 /* special case: skip DLLs, there are thousands of them! */ 334 /* special case: skip DLLs, there are thousands of them! */
335 n = strlen(name); 335 if (is_suffixed_with_case(name, ".dll"))
336 if (n > 4 && !strcasecmp(name+n-4, ".dll"))
337 return 0; 336 return 0;
338 337
339 n = open_read_close(name, buf, sizeof(buf)); 338 n = open_read_close(name, buf, sizeof(buf));