diff options
-rw-r--r-- | str.c | 20 | ||||
-rw-r--r-- | str.h | 2 |
2 files changed, 22 insertions, 0 deletions
@@ -109,3 +109,23 @@ char *argv2str(int startind, int argc, char **argv) return str; } + +char **argv_insert(char **argv, size_t *count, const char *str) +{ + argv = xrealloc(argv, (*count + 2) * sizeof(char *)); + argv[*count] = str ? xstrdup(str) : xstrdup(""); + argv[*count + 1] = NULL; + + *count += 1; + return argv; +} + +void argv_free(char **argv) +{ + char **tmp = argv; + + for (; argv && *argv; argv++) + free(*argv); + + free(tmp); +} @@ -9,5 +9,7 @@ extern int slprintf_nocheck(char *dst, size_t size, const char *fmt, ...); extern char *strtrim_right(char *p, char c); extern noinline void *xmemset(void *s, int c, size_t n); extern char *argv2str(int startind, int argc, char **argv); +extern char **argv_insert(char **argv, size_t *count, const char *str); +extern void argv_free(char **argv); #endif /* STR_H */ |