summaryrefslogtreecommitdiff
path: root/str.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-12-15 23:09:13 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-12-17 10:36:49 +0100
commit6a310b07a1c5f73998fd0ff265d5701de04ab4f1 (patch)
treee1f7a65a485f0c948fb315dd6970b9e3cd3f9f58 /str.c
parent31cab05faab92a2f0062b4833547083621d85678 (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.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/str.c b/str.c
index f4cb099..e4d8722 100644
--- a/str.c
+++ b/str.c
@@ -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);
+}