]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
string: Group str_has_prefix() and strstarts()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 11 Jul 2025 08:55:14 +0000 (11:55 +0300)
committerKees Cook <kees@kernel.org>
Thu, 17 Jul 2025 23:39:49 +0000 (16:39 -0700)
The two str_has_prefix() and strstarts() are about the same
with a slight difference on what they return. Group them in
the header.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20250711085514.1294428-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Kees Cook <kees@kernel.org>
include/linux/string.h

index 01621ad0f598ccdfae819b1a5058607e79d8a751..fdd3442c6bcbd786e177b6e87358e1065a0ffafc 100644 (file)
@@ -345,16 +345,6 @@ extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
 
 int ptr_to_hashval(const void *ptr, unsigned long *hashval_out);
 
-/**
- * strstarts - does @str start with @prefix?
- * @str: string to examine
- * @prefix: prefix to look for.
- */
-static inline bool strstarts(const char *str, const char *prefix)
-{
-       return strncmp(str, prefix, strlen(prefix)) == 0;
-}
-
 size_t memweight(const void *ptr, size_t bytes);
 
 /**
@@ -562,4 +552,14 @@ 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.
+ */
+static inline bool strstarts(const char *str, const char *prefix)
+{
+       return strncmp(str, prefix, strlen(prefix)) == 0;
+}
+
 #endif /* _LINUX_STRING_H_ */