summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-03-08 07:33:05 +0000
committerEric Andersen <andersen@codepoet.org>2001-03-08 07:33:05 +0000
commitbfb8f8f6ea438e632e808868c44af2bff196cc18 (patch)
tree64f462a3d19751199ef10a3eda192b8b023f5c0d
parent1e26922dfcadb624e4b2dd26c7d2b99477814e91 (diff)
Add strnlen
-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