summaryrefslogtreecommitdiff
path: root/libc/string
diff options
context:
space:
mode:
Diffstat (limited to 'libc/string')
-rw-r--r--libc/string/Makefile2
-rw-r--r--libc/string/string.c10
2 files changed, 11 insertions, 1 deletions
diff --git a/libc/string/Makefile b/libc/string/Makefile
index 02a69dfbf..6823f2759 100644
--- a/libc/string/Makefile
+++ b/libc/string/Makefile
@@ -27,7 +27,7 @@ LIBC=$(TOPDIR)libc.a
MSRC=string.c
MOBJ=strlen.o strcat.o strcpy.o strchr.o strcmp.o strncat.o strncpy.o \
strncmp.o strrchr.o strdup.o memcpy.o memccpy.o memset.o \
- memmove.o memcmp.o memchr.o ffs.o
+ memmove.o memcmp.o memchr.o ffs.o strnlen.o
MSRC1=index.c
MOBJ1=index.o rindex.o
diff --git a/libc/string/string.c b/libc/string/string.c
index f77cf4c69..29ac83a24 100644
--- a/libc/string/string.c
+++ b/libc/string/string.c
@@ -23,6 +23,16 @@ size_t strlen(const char *str)
}
#endif
+/********************** Function strnlen ************************************/
+
+#ifdef L_strnlen
+size_t strnlen (const char *string, size_t maxlen)
+{
+ const char *end = memchr (string, '\0', maxlen);
+ return end ? end - string : maxlen;
+}
+#endif
+
/********************** Function strcat ************************************/
#ifdef L_strcat