Browse Source

Add strnlen

Eric Andersen 24 years ago
parent
commit
bfb8f8f6ea
2 changed files with 11 additions and 1 deletions
  1. 1 1
      libc/string/Makefile
  2. 10 0
      libc/string/string.c

+ 1 - 1
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

+ 10 - 0
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