X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=klibc%2Fklibc%2Fstrncasecmp.c;h=3309d1a7fe6b4074f3285b6d4a764007ab8b9085;hp=542493de0f83e541c5a623ec70a5e51413b31239;hb=3555a14bae9f372385e4bc01368027cdbc29384c;hpb=02cbdf5eb9af4af5c3f612990ac3250bdd2135c7 diff --git a/klibc/klibc/strncasecmp.c b/klibc/klibc/strncasecmp.c index 542493de0..3309d1a7f 100644 --- a/klibc/klibc/strncasecmp.c +++ b/klibc/klibc/strncasecmp.c @@ -7,18 +7,17 @@ int strncasecmp(const char *s1, const char *s2, size_t n) { - char *n1, *n2; - int i, retval; + const unsigned char *c1 = s1, *c2 = s2; + unsigned char ch; + int d = 0; - n1 = strndup(s1, n); - n2 = strndup(s2, n); + while ( n-- ) { + /* toupper() expects an unsigned char (implicitly cast to int) + as input, and returns an int, which is exactly what we want. */ + d = toupper(ch = *c1++) - toupper(*c2++); + if ( d || !ch ) + break; + } - for (i = 0; i < strlen(n1); i++) - n1[i] = toupper(n1[i]); - for (i = 0; i < strlen(n2); i++) - n2[i] = toupper(n2[i]); - retval = strcmp(n1, n2); - free(n1); - free(n2); - return retval; + return d; }