From f4478fca7deea454ae169e2d65db2114475a279d Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sat, 15 Aug 2020 15:42:58 -0400 Subject: implement --- src/strings/strcasecmp.c | 17 ++++++++++++++++- src/strings/strncasecmp.c | 22 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) (limited to 'src/strings') diff --git a/src/strings/strcasecmp.c b/src/strings/strcasecmp.c index e9006fe2..a5955f4e 100644 --- a/src/strings/strcasecmp.c +++ b/src/strings/strcasecmp.c @@ -1,8 +1,23 @@ #include +#include int strcasecmp(const char *s1, const char *s2) { - return strcasecmp_l (s1, s2, (locale_t)0); + while (*s1 && *s2) { + char c1 = tolower(*s1); + char c2 = tolower(*s2); + if (c1 != c2) { + return c1 - c2; + } + } + + if (*s1) { + return -1; + } else if (*s2) { + return 1; + } + + return 0; } /* diff --git a/src/strings/strncasecmp.c b/src/strings/strncasecmp.c index 8094ccd2..fc02e734 100644 --- a/src/strings/strncasecmp.c +++ b/src/strings/strncasecmp.c @@ -1,8 +1,28 @@ #include +#include int strncasecmp(const char *s1, const char *s2, size_t n) { - return strncasecmp_l (s1, s2, n, (locale_t)0); + while (n > 0 && *s1 && *s2) { + char c1 = tolower(*s1); + char c2 = tolower(*s2); + if (c1 != c2) { + return c1 - c2; + } + n--; + } + + if (n == 0) { + return 0; + } + + if (*s1) { + return -1; + } else if (*s2) { + return 1; + } + + return 0; } /* -- cgit v1.2.1