summaryrefslogtreecommitdiff
path: root/user/lib/strncmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'user/lib/strncmp.c')
-rw-r--r--user/lib/strncmp.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/user/lib/strncmp.c b/user/lib/strncmp.c
new file mode 100644
index 0000000..e890517
--- /dev/null
+++ b/user/lib/strncmp.c
@@ -0,0 +1,11 @@
+#include <string.h>
+
+int strncmp(const char *restrict lhs, const char *restrict rhs, size_t n)
+{
+ const unsigned char *l = (void *)lhs, *r = (void *)rhs;
+ if (!n--)
+ return 0;
+ for (; *l && *r && n && *l == *r; l++, r++, n--)
+ ;
+ return *l - *r;
+}