Skip to content

Commit 96395cb

Browse files
committed
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>
1 parent 3caeafc commit 96395cb

7 files changed

Lines changed: 13 additions & 20 deletions

File tree

‎tools/include/linux/string.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ extern size_t strlcpy(char *dest, const char *src, size_t size);
1818

1919
char *str_error_r(int errnum, char *buf, size_t buflen);
2020

21+
int prefixcmp(const char *str, const char *prefix);
22+
2123
#endif /* _LINUX_STRING_H_ */

‎tools/lib/string.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,12 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size)
8787
}
8888
return ret;
8989
}
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+
}

‎tools/lib/subcmd/help.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33
#include <string.h>
4+
#include <linux/string.h>
45
#include <termios.h>
56
#include <sys/ioctl.h>
67
#include <sys/types.h>

‎tools/lib/subcmd/parse-options.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <linux/compiler.h>
2+
#include <linux/string.h>
23
#include <linux/types.h>
34
#include <stdio.h>
45
#include <stdlib.h>

‎tools/lib/subcmd/subcmd-util.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,4 @@ static inline void astrcat(char **out, const char *add)
7979
free(tmp);
8080
}
8181

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-
9182
#endif /* __SUBCMD_UTIL_H */

‎tools/perf/util/strbuf.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
#include <linux/kernel.h>
44
#include <errno.h>
55

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-
156
/*
167
* Used as the default ->buf value, so that people can always assume
178
* buf is non NULL and ->buf is NUL terminated even for a freshly

‎tools/perf/util/util.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
3030

3131
void set_warning_routine(void (*routine)(const char *err, va_list params));
3232

33-
int prefixcmp(const char *str, const char *prefix);
34-
3533
static inline void *zalloc(size_t size)
3634
{
3735
return calloc(1, size);

0 commit comments

Comments
 (0)