2 * Helper function for splitting a string into an argv-like array.
5 #include <linux/kernel.h>
6 #include <linux/ctype.h>
9 static const char *skip_sep(const char *cp)
11 while (*cp && isspace(*cp))
17 static const char *skip_arg(const char *cp)
19 while (*cp && !isspace(*cp))
25 static int count_argc(const char *str)
41 * argv_free - free an argv
42 * @argv - the argument vector to be freed
44 * Frees an argv and the strings it points to.
46 void argv_free(char **argv)
49 for (p = argv; *p; p++)
54 EXPORT_SYMBOL(argv_free);
57 * argv_split - split a string at whitespace, returning an argv
58 * @gfp: the GFP mask used to allocate memory
59 * @str: the string to be split
60 * @argcp: returned argument count
62 * Returns an array of pointers to strings which are split out from
63 * @str. This is performed by strictly splitting on white-space; no
64 * quote processing is performed. Multiple whitespace characters are
65 * considered to be a single argument separator. The returned array
66 * is always NULL-terminated. Returns NULL on memory allocation
69 char **argv_split(gfp_t gfp, const char *str, int *argcp)
71 int argc = count_argc(str);
72 char **argv = kzalloc(sizeof(*argv) * (argc+1), gfp);
90 t = kstrndup(p, str-p, gfp);
105 EXPORT_SYMBOL(argv_split);