diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2015-12-15 23:09:13 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2015-12-17 10:36:49 +0100 |
commit | 6a310b07a1c5f73998fd0ff265d5701de04ab4f1 (patch) | |
tree | e1f7a65a485f0c948fb315dd6970b9e3cd3f9f58 /str.c | |
parent | 31cab05faab92a2f0062b4833547083621d85678 (diff) |
str: Add helper to extend dynamically argv list
Add argv_insert function to dynamically insert string
into argv list.
Also added argv_free func to easy free dynamically allocated
argv list.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'str.c')
-rw-r--r-- | str.c | 20 |
1 files changed, 20 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); +} |