diff options
| author | Rasmus Villemoes <[email protected]> | 2026-07-08 22:37:07 +0200 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-07-21 13:51:07 -0600 |
| commit | 13822d7f42706da356368f1389f8de10ac9869a5 (patch) | |
| tree | fd12cfe4a10855e826ebdc7f692380f65fb29be2 /lib/string.c | |
| parent | 07fcb18623b4d4ad604668cfccb63890ce300ce5 (diff) | |
string: add strcasestr()
While this is not likely needed by any "real" driver code, a later
convenience addition to the "config" command will need this. As usual,
the linker will throw it away if nothing actually uses it, so it
should have no size impact when not used.
Reviewed-by: Simon Glass <[email protected]>
Signed-off-by: Rasmus Villemoes <[email protected]>
Diffstat (limited to 'lib/string.c')
| -rw-r--r-- | lib/string.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c index 20c934c18c3..dbf2ce340df 100644 --- a/lib/string.c +++ b/lib/string.c @@ -701,6 +701,33 @@ char *strstr(const char *s1, const char *s2) } #endif +/** + * strcasestr() - Case insensitive substring search + * + * @haystack: string to be searched + * @needle: string to search for + * + * Return: pointer to the first occurrence or NULL + * + * The case of both strings are ignored. + */ +char *strcasestr(const char *haystack, const char *needle) +{ + size_t l1, l2; + + l1 = strlen(haystack); + l2 = strlen(needle); + + while (l1 >= l2) { + if (!strncasecmp(haystack, needle, l2)) + return (char *)haystack; + haystack++; + l1--; + } + + return NULL; +} + #ifndef __HAVE_ARCH_MEMCHR /** * memchr - Find a character in an area of memory. |
