summaryrefslogtreecommitdiff
path: root/libc/string/strncasecmp.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-02-12 20:28:12 +0000
committerEric Andersen <andersen@codepoet.org>2002-02-12 20:28:12 +0000
commitce4b0fa7e84539992a0cccb618c4fc9d9cfabc50 (patch)
treebe09bc4851bc285f96bdb32abad8d98b79ebdc9c /libc/string/strncasecmp.c
parentf3aece684ded006182453378e8037b2b2cd290b8 (diff)
Mark Robson noticed that our strcasecmp() behaviour was not
standards compliant. Brian Stafford then provided these new implementations, which apprear to properly follow SUSv2. -Erik
Diffstat (limited to 'libc/string/strncasecmp.c')
-rw-r--r--libc/string/strncasecmp.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/libc/string/strncasecmp.c b/libc/string/strncasecmp.c
index ba73e6f09..a1bb15574 100644
--- a/libc/string/strncasecmp.c
+++ b/libc/string/strncasecmp.c
@@ -6,17 +6,18 @@
#include <string.h>
#include <ctype.h>
-int strncasecmp( const char *s, const char *d, size_t l)
+int strncasecmp (const char *a, const char *b, size_t len)
{
- while (l > 0) {
- if (*s != *d) {
- if (tolower(*s) != tolower(*d))
- return *s - *d;
- } else if (*s == '\0')
- return 0;
- s++;
- d++;
- l--;
- }
+ register int n;
+
+ if (len < 1)
return 0;
+ while (*a == *b || (n = tolower (*a) - tolower (*b)) == 0)
+ {
+ if (*a == '\0' || --len < 1)
+ return 0;
+ a++, b++;
+ }
+ return n;
}
+