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 <vadi...@gmail.com>
---
 str.c | 20 ++++++++++++++++++++
 str.h |  2 ++
 2 files changed, 22 insertions(+)

diff --git a/str.c b/str.c
index f4cb099..6c42b5d 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, int *count, char *str)
+{
+       argv = (char **)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..8de9e11 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, int *count, char *str);
+extern void argv_free(char **argv);
 
 #endif /* STR_H */
-- 
2.6.3

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to