Skip to content

Commit 7bd330d

Browse files
committed
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>
1 parent bd9860b commit 7bd330d

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎tools/include/linux/string.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ static inline bool strstarts(const char *str, const char *prefix)
2929
return strncmp(str, prefix, strlen(prefix)) == 0;
3030
}
3131

32-
#endif /* _LINUX_STRING_H_ */
32+
extern char * __must_check skip_spaces(const char *);
33+
34+
#endif /* _TOOLS_LINUX_STRING_H_ */

‎tools/lib/string.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <string.h>
1818
#include <errno.h>
1919
#include <linux/string.h>
20+
#include <linux/ctype.h>
2021
#include <linux/compiler.h>
2122

2223
/**
@@ -106,3 +107,16 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size)
106107
}
107108
return ret;
108109
}
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+
*/
117+
char *skip_spaces(const char *str)
118+
{
119+
while (isspace(*str))
120+
++str;
121+
return (char *)str;
122+
}

0 commit comments

Comments
 (0)