From 05b6b2a9efa4b40b7bc1668f887b7d98f719efb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 28 Apr 2025 14:40:02 +0200 Subject: tools/nolibc: add strstr() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is used in various selftests and will be handy when integrating those with nolibc. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-1-3c043eeab06c@linutronix.de Signed-off-by: Thomas Weißschuh --- tools/include/nolibc/string.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tools/include') diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index febfd6978966..163a17e7dd38 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -292,6 +292,26 @@ char *strrchr(const char *s, int c) return (char *)ret; } +static __attribute__((unused)) +char *strstr(const char *haystack, const char *needle) +{ + size_t len_haystack, len_needle; + + len_needle = strlen(needle); + if (!len_needle) + return NULL; + + len_haystack = strlen(haystack); + while (len_haystack >= len_needle) { + if (!memcmp(haystack, needle, len_needle)) + return (char *)haystack; + haystack++; + len_haystack--; + } + + return NULL; +} + static __attribute__((unused)) int tolower(int c) { -- cgit v1.2.3