diff options
-rw-r--r-- | src/strings/strcasecmp.c | 17 | ||||
-rw-r--r-- | src/strings/strncasecmp.c | 22 |
2 files changed, 37 insertions, 2 deletions
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 <strings.h> +#include <ctype.h> 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 <strings.h> +#include <ctype.h> 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; } /* |