strstarts: helper function for !strncmp(str, prefix, strlen(prefix))
PATCH 4/9 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 <[email protected]>
Cc Jeff Arnold <[email protected]>
Cc Tim Abbott <[email protected]>
Signed-off-by Rusty Russell <[email protected]>
--- include/linux/string.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/string.h +9 -0
@@ -114,5 +114,14 @@ extern ssize_t memory_read_from_buffer(vextern 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_ */