summaryrefslogtreecommitdiff
path: root/lib/string.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2025-02-12 08:41:36 -0600
committerTom Rini <trini@konsulko.com>2025-02-12 12:37:30 -0600
commit9b35357b95e30fd670869b4348159b65e102cc82 (patch)
tree2aee5b7566dc114ee0f02c4507c94885d1eb72d2 /lib/string.c
parent3da1864b1f2fc3cf2b4eaa1849bcafa669ff674c (diff)
parenta091d173e32b98fe372b5b02d4e25c81f1bc9dc1 (diff)
Merge branch 'u-boot-net-20250212' of https://source.denx.de/u-boot/custodians/u-boot-net
CI: https://source.denx.de/u-boot/custodians/u-boot-net/-/pipelines/24577 net-lwip: * Fix incorrect selection of ethernet device on boards having more than one * Fix TFTP option processing * Make the WGET_HTTPS Kconfig symbol depend on DM_RNG lib: * Add strnstr()
Diffstat (limited to 'lib/string.c')
-rw-r--r--lib/string.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/lib/string.c b/lib/string.c
index 0e0900de8bf..d56f88d4a84 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -15,13 +15,14 @@
* reentrant and should be faster). Use only strsep() in new code, please.
*/
+#include <asm/sections.h>
#include <config.h>
+#include <limits.h>
#include <linux/compiler.h>
-#include <linux/types.h>
-#include <linux/string.h>
#include <linux/ctype.h>
+#include <linux/string.h>
+#include <linux/types.h>
#include <malloc.h>
-#include <asm/sections.h>
/**
* strncasecmp - Case insensitive, length-limited string comparison
@@ -679,30 +680,48 @@ char *memdup(const void *src, size_t len)
return p;
}
-#ifndef __HAVE_ARCH_STRSTR
+#ifndef __HAVE_ARCH_STRNSTR
/**
- * strstr - Find the first substring in a %NUL terminated string
- * @s1: The string to be searched
- * @s2: The string to search for
+ * strnstr() - find the first substring occurrence in a NUL terminated string
+ *
+ * @s1: string to be searched
+ * @s2: string to search for
+ * @len: maximum number of characters in s2 to consider
+ *
+ * Return: pointer to the first occurrence or NULL
*/
-char * strstr(const char * s1,const char * s2)
+char *strnstr(const char *s1, const char *s2, size_t len)
{
- int l1, l2;
+ size_t l1, l2;
+ l1 = strnlen(s1, len);
l2 = strlen(s2);
- if (!l2)
- return (char *) s1;
- l1 = strlen(s1);
- while (l1 >= l2) {
- l1--;
- if (!memcmp(s1,s2,l2))
+
+ for (; l1 >= l2; --l1, ++s1) {
+ if (!memcmp(s1, s2, l2))
return (char *) s1;
- s1++;
}
+
return NULL;
}
#endif
+#ifndef __HAVE_ARCH_STRSTR
+/**
+ * strstr() - find the first substring occurrence in a NUL terminated string
+ *
+ * @s1: string to be searched
+ * @s2: string to search for
+ * @len: maximum number of characters in s2 to consider
+ *
+ * Return: pointer to the first occurrence or NULL
+ */
+char *strstr(const char *s1, const char *s2)
+{
+ return strnstr(s1, s2, SIZE_MAX);
+}
+#endif
+
#ifndef __HAVE_ARCH_MEMCHR
/**
* memchr - Find a character in an area of memory.