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/string.h>
8 #include <linux/slab.h>
9 #include <linux/module.h>
11 static const char *skip_arg(const char *cp
)
13 while (*cp
&& !isspace(*cp
))
19 static int count_argc(const char *str
)
24 str
= skip_spaces(str
);
35 * argv_free - free an argv
36 * @argv - the argument vector to be freed
38 * Frees an argv and the strings it points to.
40 void argv_free(char **argv
)
43 for (p
= argv
; *p
; p
++)
48 EXPORT_SYMBOL(argv_free
);
51 * argv_split - split a string at whitespace, returning an argv
52 * @gfp: the GFP mask used to allocate memory
53 * @str: the string to be split
54 * @argcp: returned argument count
56 * Returns an array of pointers to strings which are split out from
57 * @str. This is performed by strictly splitting on white-space; no
58 * quote processing is performed. Multiple whitespace characters are
59 * considered to be a single argument separator. The returned array
60 * is always NULL-terminated. Returns NULL on memory allocation
63 char **argv_split(gfp_t gfp
, const char *str
, int *argcp
)
65 int argc
= count_argc(str
);
66 char **argv
= kzalloc(sizeof(*argv
) * (argc
+1), gfp
);
78 str
= skip_spaces(str
);
86 t
= kstrndup(p
, str
-p
, gfp
);
101 EXPORT_SYMBOL(argv_split
);
This page took 0.032313 seconds and 6 git commands to generate.