strprefix() is drop-in compatible with strstarts() --but see caveats below--, and provides more functionality for cases where we're interested in the position where the prefix ends in the string. strprefix() returns a pointer that can be converted to bool. This is converted implicitly in most places, but if the target type is not bool, then it might be problematic and require an explicit conversion with !!. I checked that we don't need this anywhere, and also, I expect the compiler would likely diagnose in such a case, so this should be safe. Signed-off-by: Alejandro Colomar --- include/linux/string.h | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/include/linux/string.h b/include/linux/string.h index 013c6169def0..0a466360dbb3 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -609,6 +609,7 @@ static inline const char *strprefix(const char *s, const char *prefix) return strncmp(s, prefix, len) == 0 ? s + len : NULL; } #define strprefix(s, pfx) const_cast(CQChar_of(s) *, strprefix(s, pfx)) +#define strstarts(s, pfx) strprefix(s, pfx) // legacy alias /** * str_has_prefix - Test if a string has a given prefix @@ -632,19 +633,6 @@ static __always_inline size_t str_has_prefix(const char *str, const char *prefix return strncmp(str, prefix, len) == 0 ? len : 0; } -/** - * strstarts - does @str start with @prefix? - * @str: string to examine - * @prefix: prefix to look for. - * - * Returns: - * True if @str begins with @prefix. False in all other cases. - */ -static inline bool strstarts(const char *str, const char *prefix) -{ - return strncmp(str, prefix, strlen(prefix)) == 0; -} - /** * strends - Check if a string ends with another string. * @str: NULL-terminated string to check against @suffix -- 2.55.0