summaryrefslogtreecommitdiff
path: root/klibc/klibc/strncasecmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'klibc/klibc/strncasecmp.c')
-rw-r--r--klibc/klibc/strncasecmp.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/klibc/klibc/strncasecmp.c b/klibc/klibc/strncasecmp.c
index 542493de0f..3309d1a7fe 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;
}