diff options
author | Roland McGrath <roland@gnu.org> | 1996-03-14 11:20:23 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 1996-03-14 11:20:23 +0000 |
commit | 8d71c7b0e4f76dce251a121e07dff8212bed73f8 (patch) | |
tree | a90fd3140fbd2922cb6006150f8a89f4be0c888d /string/string.h | |
parent | 52e9a9d1187e1a2a7357f3a0f353058e14667d62 (diff) | |
download | glibc-8d71c7b0e4f76dce251a121e07dff8212bed73f8.zip glibc-8d71c7b0e4f76dce251a121e07dff8212bed73f8.tar.gz glibc-8d71c7b0e4f76dce251a121e07dff8212bed73f8.tar.bz2 |
Thu Mar 14 06:01:07 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu>
* 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.
Diffstat (limited to 'string/string.h')
-rw-r--r-- | string/string.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/string/string.h b/string/string.h index 95dcba0..49b29fd 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 |