summaryrefslogtreecommitdiffstats
path: root/include/linux/string.h
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2009-03-31 13:05:36 -0600
committerRusty Russell <rusty@rustcorp.com.au>2009-03-31 13:05:36 +1030
commit66f92cf9d415e96a5bdd6c64de8dd8418595d2fc (patch)
tree73fe062a18c14cbc96efc4adb8f65cf5421d6a6f /include/linux/string.h
parentaa0d3bb77e780054babcd289484cf4c15180111b (diff)
strstarts: helper function for !strncmp(str, prefix, strlen(prefix))
Impact: minor new API ksplice added a "starts_with" function, which seems like a common need. When people open-code it they seem to use fixed numbers rather than strlen, so it's quite a readability win (also, strncmp() almost always wants != 0 on it). So here's strstarts(). Cc: Anders Kaseorg <andersk@mit.edu> Cc: Jeff Arnold <jbarnold@mit.edu> Cc: Tim Abbott <tabbott@mit.edu> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'include/linux/string.h')
-rw-r--r--include/linux/string.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/linux/string.h b/include/linux/string.h
index d18fc198aa2..76ec218bb30 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -114,5 +114,14 @@ extern bool sysfs_streq(const char *s1, const char *s2);
extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
const void *from, size_t available);
+/**
+ * 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
#endif /* _LINUX_STRING_H_ */