diff options
| author | Bartosz Golaszewski <bartosz.golaszewski@linaro.org> | 2025-11-12 14:55:30 +0100 |
|---|---|---|
| committer | Bartosz Golaszewski <bartosz.golaszewski@linaro.org> | 2025-11-17 10:15:32 +0100 |
| commit | 197b3f3c70d61ff1c7ca24f66d567e06fe8ed3d9 (patch) | |
| tree | 58269d68e3ebd0b7c3058dc2a8d5c111a83dc456 /include | |
| parent | 3a8660878839faadb4f1a6dd72c3179c1df56787 (diff) | |
string: provide strends()
Implement a function for checking if a string ends with a different
string and add its kunit test cases.
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20251112-gpio-shared-v4-1-b51f97b1abd8@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/string.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/string.h b/include/linux/string.h index fdd3442c6bcb..929d05d1247c 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -562,4 +562,22 @@ 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 + * @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 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_ */ |
