summaryrefslogtreecommitdiff
path: root/str.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-11-07 16:55:15 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-11-09 13:33:21 +0100
commitc6aeff438d452be679cc3ba0a600db1d204b49a6 (patch)
tree03ad8f1576111b88d08dfec2c1615abab5bd4ff7 /str.c
parenta2a169affeb57a42e27dd4893da0bdb52542dae9 (diff)
str: Add converting cmdline args vector to str module
Move piece of code which converts cmdline args vector to string from netsniff-ng.c to str.c as function. 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.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/str.c b/str.c
index 7a5cb49..f4cb099 100644
--- a/str.c
+++ b/str.c
@@ -9,6 +9,8 @@
#include <stdarg.h>
#include "str.h"
+#include "die.h"
+#include "xmalloc.h"
size_t strlcpy(char *dest, const char *src, size_t size)
{
@@ -86,3 +88,24 @@ char *strtrim_right(char *p, char c)
return p;
}
+
+char *argv2str(int startind, int argc, char **argv)
+{
+ off_t offset = 0;
+ char *str = NULL;
+ int ret, i;
+
+ for (i = startind; i < argc; ++i) {
+ size_t alen = strlen(argv[i]) + 2;
+ size_t slen = str ? strlen(str) : 0;
+
+ str = xrealloc(str, slen + alen);
+ ret = slprintf(str + offset, strlen(argv[i]) + 2, "%s ", argv[i]);
+ if (ret < 0)
+ panic("Cannot concatenate string!\n");
+ else
+ offset += ret;
+ }
+
+ return str;
+}