From bfb8f8f6ea438e632e808868c44af2bff196cc18 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 8 Mar 2001 07:33:05 +0000 Subject: Add strnlen --- libc/string/Makefile | 2 +- libc/string/string.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'libc/string') 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 -- cgit v1.2.3