summaryrefslogtreecommitdiff
path: root/tools/include
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2025-11-02 13:46:10 +0300
committerThomas Weißschuh <linux@weissschuh.net>2025-11-02 14:11:48 +0300
commitdb75042e93cfb0bb1ecd55771cc873917074f565 (patch)
tree0cd836d20dccdfaf4bf862b78d2527e1f9998a6d /tools/include
parent09c873c91fc10eeff5f7aecb408e1ac06ffbf83b (diff)
downloadlinux-db75042e93cfb0bb1ecd55771cc873917074f565.tar.xz
tools/nolibc: add missing memchr() to string.h
Surprisingly we forgot to add this common one. It was added with a per-arch guard allowing to later implement it in arch-specific asm code like was done for a few other ones. The test verifies that we don't search past the indicated length. Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/nolibc/string.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h
index 163a17e7dd38..4000926f44ac 100644
--- a/tools/include/nolibc/string.h
+++ b/tools/include/nolibc/string.h
@@ -93,6 +93,21 @@ void *memset(void *dst, int b, size_t len)
}
#endif /* #ifndef NOLIBC_ARCH_HAS_MEMSET */
+#ifndef NOLIBC_ARCH_HAS_MEMCHR
+static __attribute__((unused))
+void *memchr(const void *s, int c, size_t len)
+{
+ char *p = (char *)s;
+
+ while (len--) {
+ if (*p == (char)c)
+ return p;
+ p++;
+ }
+ return NULL;
+}
+#endif /* #ifndef NOLIBC_ARCH_HAS_MEMCHR */
+
static __attribute__((unused))
char *strchr(const char *s, int c)
{