To avoid duplicating code in upcoming patches that will check for postfixes in strings, add strends().
Signed-off-by: Tomeu Vizoso tomeu.vizoso@collabora.com ---
Changes in v2: - Move strends to string.h
include/linux/string.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
diff --git a/include/linux/string.h b/include/linux/string.h index d5dfe3e..4244363 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -146,6 +146,19 @@ static inline bool strstarts(const char *str, const char *prefix) return strncmp(str, prefix, strlen(prefix)) == 0; }
+/** + * strends - does @str end with @postfix? + * @str: string to examine + * @postfix: postfix to look for + */ +static inline bool strends(const char *str, const char *postfix) +{ + if (strlen(str) < strlen(postfix)) + return false; + + return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; +} + size_t memweight(const void *ptr, size_t bytes); void memzero_explicit(void *s, size_t count);