[PATCH 6/8] string: add strcasestr()

Rasmus Villemoes rv at rasmusvillemoes.dk
Wed Jul 1 19:15:33 CEST 2026


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.

Signed-off-by: Rasmus Villemoes <rv at rasmusvillemoes.dk>
---
 include/linux/string.h |  1 +
 lib/string.c           | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/include/linux/string.h b/include/linux/string.h
index 5e4594b19df..93aa4cada66 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -77,6 +77,7 @@ extern __kernel_size_t strlen(const char *);
 #ifndef __HAVE_ARCH_STRNLEN
 extern __kernel_size_t strnlen(const char *,__kernel_size_t);
 #endif
+char *strcasestr(const char *, const char *);
 
 #ifndef __HAVE_ARCH_STRCSPN
 /**
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.
-- 
2.54.0



More information about the U-Boot mailing list