Add a macro of the same name, which returns a pointer that is const-qualified iff the input string is const-qualified. The return type is a possibly-const-qualified pointer to char, even if the input is a possibly-const-qualified pointer to void, which is why we require the CQChar_of() macro. The function now needs to return 'const char *', because const_cast() can only drop const, but never add it. Suggested-by: Geert Uytterhoeven Cc: Joe Perches Cc: David Laight Signed-off-by: Alejandro Colomar --- include/linux/string.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/linux/string.h b/include/linux/string.h index 5f3ac760df2e..b1468d3913f6 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -591,11 +591,12 @@ 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) +static inline const char *strprefix(const char *s, const char *prefix) { size_t len = strlen(prefix); - return strncmp(s, prefix, len) == 0 ? (char *) s + len : NULL; + return strncmp(s, prefix, len) == 0 ? s + len : NULL; } +#define strprefix(s, pfx) const_cast(CQChar_of(s) *, strprefix(s, pfx)) /** * strstarts - does @str start with @prefix? -- 2.55.0