]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
string: add strcasestr()
authorRasmus Villemoes <rv@rasmusvillemoes.dk>
Wed, 8 Jul 2026 20:37:07 +0000 (22:37 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 21 Jul 2026 19:51:07 +0000 (13:51 -0600)
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 <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
include/linux/string.h
lib/string.c

index 5e4594b19df6cf80f2c96663bbc5551439b65671..986499dfc70748887a3bccf6306bd166b28a3690 100644 (file)
@@ -71,6 +71,7 @@ extern char * strstr(const char *,const char *);
 #ifndef __HAVE_ARCH_STRNSTR
 extern char *strnstr(const char *, const char *, size_t);
 #endif
+char *strcasestr(const char *, const char *);
 #ifndef __HAVE_ARCH_STRLEN
 extern __kernel_size_t strlen(const char *);
 #endif
index 20c934c18c3f42ba76e114b371d2026710436cf3..dbf2ce340dfbe56bb180ddedc041495d43607e78 100644 (file)
@@ -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.