summaryrefslogtreecommitdiff
path: root/kern/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'kern/string.c')
-rw-r--r--kern/string.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/kern/string.c b/kern/string.c
index b77aa2f3..584030b9 100644
--- a/kern/string.c
+++ b/kern/string.c
@@ -177,6 +177,29 @@ strcmp(const char *s1, const char *s2)
}
#endif /* ARCH_STRING_STRCMP */
+#ifndef ARCH_STRING_STRNCMP
+int
+strncmp(const char *s1, const char *s2, size_t n)
+{
+ char c1, c2;
+
+ c1 = '\0';
+ c2 = '\0';
+
+ while ((n != 0) && (c1 = *s1) == (c2 = *s2)) {
+ if (c1 == '\0') {
+ return 0;
+ }
+
+ n--;
+ s1++;
+ s2++;
+ }
+
+ return (int)c1 - (int)c2;
+}
+#endif /* ARCH_STRING_STRNCMP */
+
#ifndef ARCH_STRING_STRCHR
char *
strchr(const char *s, int c)