brcm63xx: add support for registering parallel flash through dtb
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / patches-3.14 / 002-lib-add-glibc-style-strchrnul-variant.patch
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
5
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.
11
12 Signed-off-by: Grant Likely <grant.likely@linaro.org>
13 ---
14 include/linux/string.h | 3 +++
15 lib/string.c | 18 ++++++++++++++++++
16 2 files changed, 21 insertions(+)
17
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);
23 #endif
24 +#ifndef __HAVE_ARCH_STRCHRNUL
25 +extern char * strchrnul(const char *,int);
26 +#endif
27 #ifndef __HAVE_ARCH_STRNCHR
28 extern char * strnchr(const char *, size_t, int);
29 #endif
30 --- a/lib/string.c
31 +++ b/lib/string.c
32 @@ -301,6 +301,24 @@ char *strchr(const char *s, int c)
33 EXPORT_SYMBOL(strchr);
34 #endif
35
36 +#ifndef __HAVE_ARCH_STRCHRNUL
37 +/**
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
41 + *
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.
44 + */
45 +char *strchrnul(const char *s, int c)
46 +{
47 + while (*s && *s != (char)c)
48 + s++;
49 + return (char *)s;
50 +}
51 +EXPORT_SYMBOL(strchrnul);
52 +#endif
53 +
54 #ifndef __HAVE_ARCH_STRRCHR
55 /**
56 * strrchr - Find the last occurrence of a character in a string