Skip to content

Commit

Permalink
tools lib string: Adopt prefixcmp() from perf and subcmd
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Arnaldo Carvalho de Melo committed Apr 26, 2017
1 parent 3caeafc commit 96395cb
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 20 deletions.
2 changes: 2 additions & 0 deletions tools/include/linux/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ extern size_t strlcpy(char *dest, const char *src, size_t size);

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

int prefixcmp(const char *str, const char *prefix);

#endif /* _LINUX_STRING_H_ */
9 changes: 9 additions & 0 deletions tools/lib/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,12 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size)
}
return ret;
}

int prefixcmp(const char *str, const char *prefix)
{
for (; ; str++, prefix++)
if (!*prefix)
return 0;
else if (*str != *prefix)
return (unsigned char)*prefix - (unsigned char)*str;
}
1 change: 1 addition & 0 deletions tools/lib/subcmd/help.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/string.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/types.h>
Expand Down
1 change: 1 addition & 0 deletions tools/lib/subcmd/parse-options.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <linux/compiler.h>
#include <linux/string.h>
#include <linux/types.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
9 changes: 0 additions & 9 deletions tools/lib/subcmd/subcmd-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,4 @@ static inline void astrcat(char **out, const char *add)
free(tmp);
}

static inline int prefixcmp(const char *str, const char *prefix)
{
for (; ; str++, prefix++)
if (!*prefix)
return 0;
else if (*str != *prefix)
return (unsigned char)*prefix - (unsigned char)*str;
}

#endif /* __SUBCMD_UTIL_H */
9 changes: 0 additions & 9 deletions tools/perf/util/strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
#include <linux/kernel.h>
#include <errno.h>

int prefixcmp(const char *str, const char *prefix)
{
for (; ; str++, prefix++)
if (!*prefix)
return 0;
else if (*str != *prefix)
return (unsigned char)*prefix - (unsigned char)*str;
}

/*
* Used as the default ->buf value, so that people can always assume
* buf is non NULL and ->buf is NUL terminated even for a freshly
Expand Down
2 changes: 0 additions & 2 deletions tools/perf/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));

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

int prefixcmp(const char *str, const char *prefix);

static inline void *zalloc(size_t size)
{
return calloc(1, size);
Expand Down

0 comments on commit 96395cb

Please sign in to comment.