summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--str.c20
-rw-r--r--str.h2
2 files changed, 22 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);
+}
diff --git a/str.h b/str.h
index 7d078da..3ffb2b9 100644
--- a/str.h
+++ b/str.h
@@ -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 */