summaryrefslogtreecommitdiff
path: root/lib/libc/strings/strncasecmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/strings/strncasecmp.c')
-rw-r--r--lib/libc/strings/strncasecmp.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/libc/strings/strncasecmp.c b/lib/libc/strings/strncasecmp.c
new file mode 100644
index 00000000..679cf245
--- /dev/null
+++ b/lib/libc/strings/strncasecmp.c
@@ -0,0 +1,32 @@
+#include <libc.h>
+#include <ctype.h>
+#include <stddef.h>
+
+int strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ unsigned char c1, c2;
+
+ if (n == 0)
+ return 0;
+
+ while (n-- > 0 && *s1 && *s2) {
+ c1 = (unsigned char)tolower((unsigned char)*s1);
+ c2 = (unsigned char)tolower((unsigned char)*s2);
+ if (c1 != c2)
+ return c1 - c2;
+ s1++;
+ s2++;
+ }
+
+ if (n == (size_t)-1)
+ return 0;
+
+ return (unsigned char)tolower((unsigned char)*s1) -
+ (unsigned char)tolower((unsigned char)*s2);
+}
+
+weak int strncasecmp_l(const char *s1, const char *s2, size_t n,
+ locale_t unused locale)
+{
+ return strncasecmp(s1, s2, n);
+}