diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/compare_string_array.c | 28 |
1 files changed, 28 insertions, 0 deletions
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 | ||
48 | char* FAST_FUNC is_suffixed_with(const char *string, const char *key) | 49 | char* 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 | ||
64 | static 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 | |||
80 | char* FAST_FUNC is_suffixed_with(const char *string, const char *key) | ||
81 | { | ||
82 | return is_suffixed(string, key, strcmp); | ||
83 | } | ||
84 | |||
85 | char* 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) */ |