[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d7b81639-c53c-4186-9e30-04137576a1f1@t-8ch.de>
Date: Sat, 21 Jun 2025 10:27:11 +0200
From: Thomas Weißschuh <thomas@...ch.de>
To: Willy Tarreau <w@....eu>
Cc: Thomas Weißschuh <thomas.weissschuh@...utronix.de>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 4/4] tools/nolibc: add missing memchr() to string.h
On 2025-06-20 12:02:51+0200, Willy Tarreau wrote:
> 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@....eu>
> ---
> tools/include/nolibc/string.h | 15 +++++++++++++++
> tools/testing/selftests/nolibc/nolibc-test.c | 2 ++
> 2 files changed, 17 insertions(+)
>
> diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h
> index 163a17e7dd38b..4000926f44ac4 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
So far we only have added these guards when necessary,
which they aren't here. Can we drop them?
> +static __attribute__((unused))
> +void *memchr(const void *s, int c, size_t len)
> +{
> + char *p = (char *)s;
The docs say that they are interpreted as "unsigned char".
Also, can we keep the const?
> +
> + 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)
> {
<snip>
Powered by blists - more mailing lists