/* Returns an array of pointers to strings which are split out from @str. This is performed by strictly splitting on white-space; no quote processing is performed. Multiple whitespace characters are considered to be a single argument separator. The returned array is always NULL-terminated. Returns NULL on memory allocation failure.  */
char** argv_split(const char *str, int *argcp)
/* Returns an array of pointers to strings which are split out from @str. This is performed by strictly splitting on white-space; no quote processing is performed. Multiple whitespace characters are considered to be a single argument separator. The returned array is always NULL-terminated. Returns NULL on memory allocation failure.  */
char** argv_split(const char *str, int *argcp)
{
	int argc = count_argc(str);
	char **argv = zalloc(sizeof(*argv) * (argc+1));
	char **argvp;
	if (argv == NULL)
		goto out;
	if (argcp)
		*argcp = argc;
	argvp = argv;
	while (*str) {
		str = skip_sep(str);
		if (*str) {
			const char *p = str;
			char *t;
			str = skip_arg(str);
			t = strndup(p, str-p);
			if (t == NULL)
				goto fail;
			*argvp++ = t;
		}
	}
	*argvp = NULL;
out:
	return argv;
fail:
	argv_free(argv);
	return NULL;
}