summary refs log tree commit diff
path: root/string/string.h
diff options
context:
space:
mode:
Diffstat (limited to 'string/string.h')
-rw-r--r--string/string.h17
1 files changed, 17 insertions, 0 deletions
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