mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-28 01:51:33 +00:00
string: Add strchrnul()
This functions works like strchr() but returns the end of the string if the character is not found. Add an implementation of this. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
a4b8e372d5
commit
6b45ba45fb
2 changed files with 21 additions and 0 deletions
|
@ -50,6 +50,19 @@ extern int strncasecmp(const char *s1, const char *s2, __kernel_size_t len);
|
||||||
#ifndef __HAVE_ARCH_STRCHR
|
#ifndef __HAVE_ARCH_STRCHR
|
||||||
extern char * strchr(const char *,int);
|
extern char * strchr(const char *,int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* strchrnul() - return position of a character in the string, or end of string
|
||||||
|
*
|
||||||
|
* The strchrnul() function is like strchr() except that if c is not found
|
||||||
|
* in s, then it returns a pointer to the nul byte at the end of s, rather than
|
||||||
|
* NULL
|
||||||
|
* @s: string to search
|
||||||
|
* @c: character to search for
|
||||||
|
* @return position of @c in @s, or end of @s if not found
|
||||||
|
*/
|
||||||
|
const char *strchrnul(const char *s, int c);
|
||||||
|
|
||||||
#ifndef __HAVE_ARCH_STRRCHR
|
#ifndef __HAVE_ARCH_STRRCHR
|
||||||
extern char * strrchr(const char *,int);
|
extern char * strrchr(const char *,int);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -230,6 +230,14 @@ char * strchr(const char * s, int c)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const char *strchrnul(const char *s, int c)
|
||||||
|
{
|
||||||
|
for (; *s != (char)c; ++s)
|
||||||
|
if (*s == '\0')
|
||||||
|
break;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef __HAVE_ARCH_STRRCHR
|
#ifndef __HAVE_ARCH_STRRCHR
|
||||||
/**
|
/**
|
||||||
* strrchr - Find the last occurrence of a character in a string
|
* strrchr - Find the last occurrence of a character in a string
|
||||||
|
|
Loading…
Add table
Reference in a new issue