From 6691b2e8d230e1c85d1a31a752f9f5b6933edbb0 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 9 Dec 2018 14:46:14 +0000 Subject: win32: add a case-insensitive version of is_suffixed_with() --- libbb/compare_string_array.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'libbb') 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) * beginning of prefix key in string. If key is an empty string return pointer * to the end of string. */ +#if !ENABLE_PLATFORM_MINGW32 char* FAST_FUNC is_suffixed_with(const char *string, const char *key) { size_t key_len = strlen(key); @@ -59,6 +60,33 @@ char* FAST_FUNC is_suffixed_with(const char *string, const char *key) return NULL; } +#else +static char* FAST_FUNC is_suffixed(const char *string, const char *key, + int (*fn)(const char *, const char*)) +{ + size_t key_len = strlen(key); + ssize_t len_diff = strlen(string) - key_len; + + if (len_diff >= 0) { + string += len_diff; + if (fn(string, key) == 0) { + return (char*)string; + } + } + + return NULL; +} + +char* FAST_FUNC is_suffixed_with(const char *string, const char *key) +{ + return is_suffixed(string, key, strcmp); +} + +char* FAST_FUNC is_suffixed_with_case(const char *string, const char *key) +{ + return is_suffixed(string, key, strcasecmp); +} +#endif /* returns the array index of the string */ /* (index of first match is returned, or -1) */ -- cgit v1.2.3-55-g6feb