aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2019-06-25 20:23:18 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-06-25 20:23:18 -0400
commit7bd330de43fd5693e90be13dac7fbd9af3b6335d (patch)
tree0e3a3029bbb61d14730f84ae08a0be89d6dd2477
parentbd9860bf050f77c4e260a9ae10a5587009ad6e07 (diff)
tools lib: Adopt skip_spaces() from the kernel sources
Same implementation, will be used to replace ad-hoc equivalent code in tools/. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: André Goddard Rosa <andre.goddard@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lkml.kernel.org/n/tip-dig691cg9ripvoiprpidthw7@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/include/linux/string.h4
-rw-r--r--tools/lib/string.c14
2 files changed, 17 insertions, 1 deletions
diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index 6c3e2cc274c5..cee239350a6b 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -29,4 +29,6 @@ static inline bool strstarts(const char *str, const char *prefix)
29 return strncmp(str, prefix, strlen(prefix)) == 0; 29 return strncmp(str, prefix, strlen(prefix)) == 0;
30} 30}
31 31
32#endif /* _LINUX_STRING_H_ */ 32extern char * __must_check skip_spaces(const char *);
33
34#endif /* _TOOLS_LINUX_STRING_H_ */
diff --git a/tools/lib/string.c b/tools/lib/string.c
index 93b3d4b6feac..50d400822bb3 100644
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -17,6 +17,7 @@
17#include <string.h> 17#include <string.h>
18#include <errno.h> 18#include <errno.h>
19#include <linux/string.h> 19#include <linux/string.h>
20#include <linux/ctype.h>
20#include <linux/compiler.h> 21#include <linux/compiler.h>
21 22
22/** 23/**
@@ -106,3 +107,16 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size)
106 } 107 }
107 return ret; 108 return ret;
108} 109}
110
111/**
112 * skip_spaces - Removes leading whitespace from @str.
113 * @str: The string to be stripped.
114 *
115 * Returns a pointer to the first non-whitespace character in @str.
116 */
117char *skip_spaces(const char *str)
118{
119 while (isspace(*str))
120 ++str;
121 return (char *)str;
122}