2 #include "argv-array.h"
5 static const char *empty_argv_storage = NULL;
6 const char **empty_argv = &empty_argv_storage;
8 void argv_array_init(struct argv_array *array)
10 array->argv = empty_argv;
15 static void argv_array_push_nodup(struct argv_array *array, const char *value)
17 if (array->argv == empty_argv)
20 ALLOC_GROW(array->argv, array->argc + 2, array->alloc);
21 array->argv[array->argc++] = value;
22 array->argv[array->argc] = NULL;
25 void argv_array_push(struct argv_array *array, const char *value)
27 argv_array_push_nodup(array, xstrdup(value));
30 void argv_array_pushf(struct argv_array *array, const char *fmt, ...)
33 struct strbuf v = STRBUF_INIT;
36 strbuf_vaddf(&v, fmt, ap);
39 argv_array_push_nodup(array, strbuf_detach(&v, NULL));
42 void argv_array_clear(struct argv_array *array)
44 if (array->argv != empty_argv) {
46 for (i = 0; i < array->argc; i++)
47 free((char **)array->argv[i]);
50 argv_array_init(array);