OSDN Git Service

Add strnlen
authorEric Andersen <andersen@codepoet.org>
Thu, 8 Mar 2001 07:33:05 +0000 (07:33 -0000)
committerEric Andersen <andersen@codepoet.org>
Thu, 8 Mar 2001 07:33:05 +0000 (07:33 -0000)
libc/string/Makefile
libc/string/string.c

index 02a69df..6823f27 100644 (file)
@@ -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
index f77cf4c..29ac83a 100644 (file)
@@ -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