From cec10062d823eb05697eb956235d4ec66ee65e92 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 2 Sep 2015 20:00:18 +0200 Subject: add memcasecmp and wmemcasecmp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/string/strcmp.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/string') diff --git a/src/string/strcmp.c b/src/string/strcmp.c index 066b7c1..bffb2ad 100644 --- a/src/string/strcmp.c +++ b/src/string/strcmp.c @@ -44,6 +44,35 @@ int memcmp(const void* a, const void* b, size_t size) } +/** + * Compare two memory segments alphabetically in a case insensitive manner. + * + * This is a slibc extension added because it was useful + * in implementing slibc itself. + * + * @param a A negative value is returned if this is the lesser. + * @param b A positive value is returned if this is the lesser. + * @param size The size of the segments. + * @return Zero is returned if `a` and `b` are equal, otherwise, + * see the specifications for `a` and `b`. + */ +int memcasecmp(const void* a, const void* b, size_t size) +{ + const signed char* s1 = a; + const signed char* s2 = b; + int c1, c2; + for (; size--; s1++, s2++) + if (*s1 != *s2) + { + c1 = isalpha(*s1) ? tolower(*s1) : (int)*s1; + c2 = isalpha(*s2) ? tolower(*s2) : (int)*s2; + if ((c1 -= c2)) + return c1; + } + return 0; +} + + /** * Compare two strings alphabetically in a case sensitive manner. * -- cgit v1.2.3-70-g09d2