summaryrefslogtreecommitdiff
path: root/na/lib/string/strnlen.c
diff options
context:
space:
mode:
Diffstat (limited to 'na/lib/string/strnlen.c')
-rw-r--r--na/lib/string/strnlen.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/na/lib/string/strnlen.c b/na/lib/string/strnlen.c
new file mode 100644
index 0000000..8931c52
--- /dev/null
+++ b/na/lib/string/strnlen.c
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: MIT */
+/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */
+
+#include <string.h>
+
+size_t strnlen(const char *s, size_t n)
+{
+ const char *p = memchr(s, 0, n);
+ return p ? p-s : n;
+}