[PATCH v6 17/19] string: Make strends() a legacy alias for strsuffix()

From: Alejandro Colomar

Date: Sat Nov 14 2026 - 10:25:19 EST


strsuffix() is drop-in compatible with strends() --but see caveats
below--, and provides more functionality for cases where we're
interested in the position of where the suffix is in the string.

strsuffix() 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 <alx@xxxxxxxxxx>
---
include/linux/string.h | 20 +-------------------
1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/include/linux/string.h b/include/linux/string.h
index 2f7fb2c70662..7469d4634b3e 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -633,6 +633,7 @@ static inline const char *strsuffix(const char *s, const char *suffix)
return streq(s + off, suffix) ? s + off : NULL;
}
#define strsuffix(s, sfx) const_cast(CQChar_of(s) *, strsuffix(s, sfx))
+#define strends(s, sfx) strsuffix(s, sfx) // legacy alias

/**
* str_has_prefix - Test if a string has a given prefix
@@ -656,23 +657,4 @@ static __always_inline size_t str_has_prefix(const char *str, const char *prefix
return strncmp(str, prefix, len) == 0 ? len : 0;
}

-/**
- * strends - Check if a string ends with another string.
- * @str: NULL-terminated string to check against @suffix
- * @suffix: NULL-terminated string defining the suffix to look for in @str
- *
- * Returns:
- * True if @str ends with @suffix. False in all other cases.
- */
-static inline bool __attribute__((nonnull(1, 2)))
-strends(const char *str, const char *suffix)
-{
- unsigned int str_len = strlen(str), suffix_len = strlen(suffix);
-
- if (str_len < suffix_len)
- return false;
-
- return !(strcmp(str + str_len - suffix_len, suffix));
-}
-
#endif /* _LINUX_STRING_H_ */
--
2.55.0

Attachment: signature.asc
Description: PGP signature