Re: [PATCH v3 5/5] string: Make strprefix() const-qualifier-generic
From: David Laight
Date: Wed Nov 11 2026 - 05:36:21 EST
On Tue, 10 Nov 2026 16:33:56 +0100
Alejandro Colomar <alx@xxxxxxxxxx> wrote:
> Suggested-by: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> Signed-off-by: Alejandro Colomar <alx@xxxxxxxxxx>
> ---
> include/linux/string.h | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 9e59f9697c9e..55ca4cb5122c 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -590,7 +590,9 @@ void memcpy_and_pad(void *dest, size_t dest_len, const void *src, size_t count,
> * * @s+strlen(@prefix) if @s starts with @prefix
> * * NULL if @s does not start with @prefix
> */
> -static inline char *strprefix(const char *s, const char *prefix)
> +#define strprefix(s, pfx) const_cast(CQChar_of(s) *, strprefix(s, pfx))
Isn't in enough to do:
#define strprefix(s, pfx) ((typeof(s))strprefix(s, pfx))
which correctly preserves all qualifiers.
David
> +
> +static inline char *(strprefix)(const char *s, const char *prefix)
> {
> size_t len = strlen(prefix);
> return strncmp(s, prefix, len) == 0 ? (char *) s + len : NULL;