1 From 11d200e95f3e84c1102e4cc9863a3614fd41f3ad Mon Sep 17 00:00:00 2001
2 From: Grant Likely <grant.likely@linaro.org>
3 Date: Fri, 14 Mar 2014 17:00:14 +0000
4 Subject: [PATCH] lib: add glibc style strchrnul() variant
6 The strchrnul() variant helpfully returns a the end of the string
7 instead of a NULL if the requested character is not found. This can
8 simplify string parsing code since it doesn't need to expicitly check
9 for a NULL return. If a valid string pointer is passed in, then a valid
10 null terminated string will always come back out.
12 Signed-off-by: Grant Likely <grant.likely@linaro.org>
14 include/linux/string.h | 3 +++
15 lib/string.c | 18 ++++++++++++++++++
16 2 files changed, 21 insertions(+)
18 --- a/include/linux/string.h
19 +++ b/include/linux/string.h
20 @@ -52,6 +52,9 @@ extern int strncasecmp(const char *s1, c
21 #ifndef __HAVE_ARCH_STRCHR
22 extern char * strchr(const char *,int);
24 +#ifndef __HAVE_ARCH_STRCHRNUL
25 +extern char * strchrnul(const char *,int);
27 #ifndef __HAVE_ARCH_STRNCHR
28 extern char * strnchr(const char *, size_t, int);
32 @@ -301,6 +301,24 @@ char *strchr(const char *s, int c)
33 EXPORT_SYMBOL(strchr);
36 +#ifndef __HAVE_ARCH_STRCHRNUL
38 + * strchrnul - Find and return a character in a string, or end of string
39 + * @s: The string to be searched
40 + * @c: The character to search for
42 + * Returns pointer to first occurrence of 'c' in s. If c is not found, then
43 + * return a pointer to the null byte at the end of s.
45 +char *strchrnul(const char *s, int c)
47 + while (*s && *s != (char)c)
51 +EXPORT_SYMBOL(strchrnul);
54 #ifndef __HAVE_ARCH_STRRCHR
56 * strrchr - Find the last occurrence of a character in a string