diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-26 14:49:21 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-26 14:49:21 -0400 |
commit | 96395cbbc7e94cbbe4f76cf64cf122fabc19123d (patch) | |
tree | c0cf51cd06c2b98bf45ef786f88c9b662c6645e8 | |
parent | 3caeafce5392a8eba7b36d0d097d403cacc66e2d (diff) |
tools lib string: Adopt prefixcmp() from perf and subcmd
Both had copies originating from git.git, move those to
tools/lib/string.c, getting both tools/lib/subcmd/ and tools/perf/ to
use it.
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: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-uidwtticro1qhttzd2rkrkg1@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/include/linux/string.h | 2 | ||||
-rw-r--r-- | tools/lib/string.c | 9 | ||||
-rw-r--r-- | tools/lib/subcmd/help.c | 1 | ||||
-rw-r--r-- | tools/lib/subcmd/parse-options.c | 1 | ||||
-rw-r--r-- | tools/lib/subcmd/subcmd-util.h | 9 | ||||
-rw-r--r-- | tools/perf/util/strbuf.c | 9 | ||||
-rw-r--r-- | tools/perf/util/util.h | 2 |
7 files changed, 13 insertions, 20 deletions
diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h index f436d2420a18..d62b56cf8c12 100644 --- a/tools/include/linux/string.h +++ b/tools/include/linux/string.h | |||
@@ -18,4 +18,6 @@ extern size_t strlcpy(char *dest, const char *src, size_t size); | |||
18 | 18 | ||
19 | char *str_error_r(int errnum, char *buf, size_t buflen); | 19 | char *str_error_r(int errnum, char *buf, size_t buflen); |
20 | 20 | ||
21 | int prefixcmp(const char *str, const char *prefix); | ||
22 | |||
21 | #endif /* _LINUX_STRING_H_ */ | 23 | #endif /* _LINUX_STRING_H_ */ |
diff --git a/tools/lib/string.c b/tools/lib/string.c index bd239bc1d557..8e678af1c6ee 100644 --- a/tools/lib/string.c +++ b/tools/lib/string.c | |||
@@ -87,3 +87,12 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size) | |||
87 | } | 87 | } |
88 | return ret; | 88 | return ret; |
89 | } | 89 | } |
90 | |||
91 | int prefixcmp(const char *str, const char *prefix) | ||
92 | { | ||
93 | for (; ; str++, prefix++) | ||
94 | if (!*prefix) | ||
95 | return 0; | ||
96 | else if (*str != *prefix) | ||
97 | return (unsigned char)*prefix - (unsigned char)*str; | ||
98 | } | ||
diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c index e228c3cb3716..ba970a73d053 100644 --- a/tools/lib/subcmd/help.c +++ b/tools/lib/subcmd/help.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <string.h> | 3 | #include <string.h> |
4 | #include <linux/string.h> | ||
4 | #include <termios.h> | 5 | #include <termios.h> |
5 | #include <sys/ioctl.h> | 6 | #include <sys/ioctl.h> |
6 | #include <sys/types.h> | 7 | #include <sys/types.h> |
diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c index 6bc24025d054..359bfa77f39c 100644 --- a/tools/lib/subcmd/parse-options.c +++ b/tools/lib/subcmd/parse-options.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #include <linux/compiler.h> | 1 | #include <linux/compiler.h> |
2 | #include <linux/string.h> | ||
2 | #include <linux/types.h> | 3 | #include <linux/types.h> |
3 | #include <stdio.h> | 4 | #include <stdio.h> |
4 | #include <stdlib.h> | 5 | #include <stdlib.h> |
diff --git a/tools/lib/subcmd/subcmd-util.h b/tools/lib/subcmd/subcmd-util.h index fc2e45d8aaf1..8fa5f036eff0 100644 --- a/tools/lib/subcmd/subcmd-util.h +++ b/tools/lib/subcmd/subcmd-util.h | |||
@@ -79,13 +79,4 @@ static inline void astrcat(char **out, const char *add) | |||
79 | free(tmp); | 79 | free(tmp); |
80 | } | 80 | } |
81 | 81 | ||
82 | static inline int prefixcmp(const char *str, const char *prefix) | ||
83 | { | ||
84 | for (; ; str++, prefix++) | ||
85 | if (!*prefix) | ||
86 | return 0; | ||
87 | else if (*str != *prefix) | ||
88 | return (unsigned char)*prefix - (unsigned char)*str; | ||
89 | } | ||
90 | |||
91 | #endif /* __SUBCMD_UTIL_H */ | 82 | #endif /* __SUBCMD_UTIL_H */ |
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c index e91b5e86f027..aafe908b82b5 100644 --- a/tools/perf/util/strbuf.c +++ b/tools/perf/util/strbuf.c | |||
@@ -3,15 +3,6 @@ | |||
3 | #include <linux/kernel.h> | 3 | #include <linux/kernel.h> |
4 | #include <errno.h> | 4 | #include <errno.h> |
5 | 5 | ||
6 | int prefixcmp(const char *str, const char *prefix) | ||
7 | { | ||
8 | for (; ; str++, prefix++) | ||
9 | if (!*prefix) | ||
10 | return 0; | ||
11 | else if (*str != *prefix) | ||
12 | return (unsigned char)*prefix - (unsigned char)*str; | ||
13 | } | ||
14 | |||
15 | /* | 6 | /* |
16 | * Used as the default ->buf value, so that people can always assume | 7 | * Used as the default ->buf value, so that people can always assume |
17 | * buf is non NULL and ->buf is NUL terminated even for a freshly | 8 | * buf is non NULL and ->buf is NUL terminated even for a freshly |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index d620719775a8..5dfb9bb6482d 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -30,8 +30,6 @@ void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); | |||
30 | 30 | ||
31 | void set_warning_routine(void (*routine)(const char *err, va_list params)); | 31 | void set_warning_routine(void (*routine)(const char *err, va_list params)); |
32 | 32 | ||
33 | int prefixcmp(const char *str, const char *prefix); | ||
34 | |||
35 | static inline void *zalloc(size_t size) | 33 | static inline void *zalloc(size_t size) |
36 | { | 34 | { |
37 | return calloc(1, size); | 35 | return calloc(1, size); |