/* * strncasecmp() - Compare the first n characters of two strings * (or the entire string if the limit is greater than the total * string length) case-insensitively. * * Dan Cross */ #include #include #include int strncasecmp(const char *s1, const char *s2, size_t len) { int c1, c2; char *a, *b; c1 = c2 = 0; a = (char *)s1; b = (char *)s2; while (len-- > 0) { c1 = (isascii(*a) && islower(*a)) ? *a : tolower(*a); c2 = (isascii(*b) && islower(*b)) ? *b : tolower(*b); if (c1 == '\0' || c2 == '\0' || c1 != c2) break; a++; b++; } return((c1 == c2) ? 0 : (c1 < c2) ? -1 : 1); } int strcasecmp(const char *s1, const char *s2) { return(strncasecmp(s1, s2, strlen(s1) + 1)); /* Include nul. */ }