aboutsummaryrefslogtreecommitdiffstats
path: root/tools/include/linux/string.h
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2017-07-20 14:27:39 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-07-20 14:46:10 -0400
commit8e99b6d4533cf3f49dcd813155a513a5b572baef (patch)
treef3f082ab6d3e1916353b59e7f70735183cc72722 /tools/include/linux/string.h
parent082ab9a18e532864d1ceecfb50221df62b1d5a92 (diff)
tools include: Adopt strstarts() from the kernel
Replacing prefixcmp(), same purpose, inverted result, so standardize on the kernel variant, to reduce silly differences among tools/ and the kernel sources, making it easier for people to work in both codebases. And then doing: if (strstarts(option, "no-")) Looks clearer than doing: if (!prefixcmp(option, "no-")) To figure out if option starts witn "no-". Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-kaei42gi7lpa8subwtv7eug8@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/include/linux/string.h')
-rw-r--r--tools/include/linux/string.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index d62b56cf8c12..a30fad536f52 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -1,8 +1,8 @@
1#ifndef _TOOLS_LINUX_STRING_H_ 1#ifndef _TOOLS_LINUX_STRING_H_
2#define _TOOLS_LINUX_STRING_H_ 2#define _TOOLS_LINUX_STRING_H_
3 3
4
5#include <linux/types.h> /* for size_t */ 4#include <linux/types.h> /* for size_t */
5#include <string.h>
6 6
7void *memdup(const void *src, size_t len); 7void *memdup(const void *src, size_t len);
8 8
@@ -18,6 +18,14 @@ extern size_t strlcpy(char *dest, const char *src, size_t size);
18 18
19char *str_error_r(int errnum, char *buf, size_t buflen); 19char *str_error_r(int errnum, char *buf, size_t buflen);
20 20
21int prefixcmp(const char *str, const char *prefix); 21/**
22 * strstarts - does @str start with @prefix?
23 * @str: string to examine
24 * @prefix: prefix to look for.
25 */
26static inline bool strstarts(const char *str, const char *prefix)
27{
28 return strncmp(str, prefix, strlen(prefix)) == 0;
29}
22 30
23#endif /* _LINUX_STRING_H_ */ 31#endif /* _LINUX_STRING_H_ */