From 8d71c7b0e4f76dce251a121e07dff8212bed73f8 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 14 Mar 1996 11:20:23 +0000 Subject: Thu Mar 14 06:01:07 1996 Roland McGrath * string/strnlen.c: New file. * string/Makefile (routines): Add strnlen. * string/string.h [__USE_GNU] (strnlen): Declare new function. [__OPTIMIZE__]: Define extern inline implementation of it. --- string/string.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'string/string.h') diff --git a/string/string.h b/string/string.h index 95dcba0041..49b29fd168 100644 --- a/string/string.h +++ b/string/string.h @@ -127,9 +127,26 @@ extern __ptr_t memmem __P ((__const __ptr_t __haystack, size_t __haystacklen, __const __ptr_t __needle, size_t __needlelen)); #endif + /* Return the length of S. */ extern size_t strlen __P ((__const char *__s)); +#ifdef __USE_GNU +/* Find the length of STRING, but scan at most MAXLEN characters. + If no '\0' terminator is found in that many characters, return MAXLEN. */ +extern size_t strnlen __P ((__const char *__string, size_t __maxlen)); + +#ifdef __OPTIMIZE__ +extern __inline size_t +strnlen (__const char *__string, size_t __maxlen) +{ + __const char *__end = memchr (__string, '\0', __maxlen); + return __end ? __end - __string : __maxlen; +} +#endif +#endif + + /* Return a string describing the meaning of the `errno' code in ERRNUM. */ extern char *strerror __P ((int __errnum)); #ifdef __USE_REENTRANT -- cgit v1.2.3