summaryrefslogtreecommitdiff
path: root/na/lib/string/strncmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'na/lib/string/strncmp.c')
-rw-r--r--na/lib/string/strncmp.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/na/lib/string/strncmp.c b/na/lib/string/strncmp.c
new file mode 100644
index 0000000..b98473b
--- /dev/null
+++ b/na/lib/string/strncmp.c
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: MIT */
+/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */
+
+#include <string.h>
+
+int strncmp(const char *_l, const char *_r, size_t n)
+{
+ const unsigned char *l=(void *)_l, *r=(void *)_r;
+ if (!n--) return 0;
+ for (; *l && *r && n && *l == *r ; l++, r++, n--);
+ return *l - *r;
+}