2 * Helper function for splitting a string into an argv-like array.
5 #include <linux/kernel.h>
6 #include <linux/ctype.h>
7 #include <linux/slab.h>
8 #include <linux/module.h>
10 static const char *skip_sep(const char *cp)
12 while (*cp && isspace(*cp))
18 static const char *skip_arg(const char *cp)
20 while (*cp && !isspace(*cp))
26 static int count_argc(const char *str)
42 * argv_free - free an argv
43 * @argv - the argument vector to be freed
45 * Frees an argv and the strings it points to.
47 void argv_free(char **argv)
50 for (p = argv; *p; p++)
55 EXPORT_SYMBOL(argv_free);
58 * argv_split - split a string at whitespace, returning an argv
59 * @gfp: the GFP mask used to allocate memory
60 * @str: the string to be split
61 * @argcp: returned argument count
63 * Returns an array of pointers to strings which are split out from
64 * @str. This is performed by strictly splitting on white-space; no
65 * quote processing is performed. Multiple whitespace characters are
66 * considered to be a single argument separator. The returned array
67 * is always NULL-terminated. Returns NULL on memory allocation
70 char **argv_split(gfp_t gfp, const char *str, int *argcp)
72 int argc = count_argc(str);
73 char **argv = kzalloc(sizeof(*argv) * (argc+1), gfp);
93 t = kstrndup(p, str-p, gfp);
108 EXPORT_SYMBOL(argv_split);