X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/a3d08fcd5120d2aa8303b6349ca8b14e3f284af3..91447636331957f3d9b5ca5b508f07c526b0074d:/osfmk/device/subrs.c?ds=sidebyside diff --git a/osfmk/device/subrs.c b/osfmk/device/subrs.c index 1282fd398..d652244e9 100644 --- a/osfmk/device/subrs.c +++ b/osfmk/device/subrs.c @@ -166,6 +166,49 @@ strncmp( return 0; } + +// +// Lame implementation just for use by strcasecmp/strncasecmp +// +static int +tolower(unsigned char ch) +{ + if (ch >= 'A' && ch <= 'Z') + ch = 'a' + (ch - 'A'); + + return ch; +} + +int +strcasecmp(const char *s1, const char *s2) +{ + const unsigned char *us1 = (const u_char *)s1, + *us2 = (const u_char *)s2; + + while (tolower(*us1) == tolower(*us2++)) + if (*us1++ == '\0') + return (0); + return (tolower(*us1) - tolower(*--us2)); +} + +int +strncasecmp(const char *s1, const char *s2, size_t n) +{ + if (n != 0) { + const unsigned char *us1 = (const u_char *)s1, + *us2 = (const u_char *)s2; + + do { + if (tolower(*us1) != tolower(*us2++)) + return (tolower(*us1) - tolower(*--us2)); + if (*us1++ == '\0') + break; + } while (--n != 0); + } + return (0); +} + + /* * Abstract: * strcpy copies the contents of the string "from" including