diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-06-09 02:37:33 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-06-09 02:37:33 -0400 |
commit | f6e7ffdf3fe8e3ed5e659f747946461350ade5a8 (patch) | |
tree | d261964cafdd51154b1ad757574f508da2d9ad76 /src/basic/strv.c | |
parent | 566cac15ed36506e2bb766313a5d4e0825bc6499 (diff) | |
parent | 022ed72eff07ca6c1409747e774ef5b35724c9df (diff) |
Merge tag 'v230-3.parabola1' into parabola
Diffstat (limited to 'src/basic/strv.c')
-rw-r--r-- | src/basic/strv.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/basic/strv.c b/src/basic/strv.c index b5d4d8191b..97a96e5762 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -371,7 +371,7 @@ char *strv_join(char **l, const char *separator) { n = 0; STRV_FOREACH(s, l) { - if (n != 0) + if (s != l) n += k; n += strlen(*s); } @@ -382,7 +382,7 @@ char *strv_join(char **l, const char *separator) { e = r; STRV_FOREACH(s, l) { - if (e != r) + if (s != l) e = stpcpy(e, separator); e = stpcpy(e, *s); @@ -558,6 +558,42 @@ int strv_extend(char ***l, const char *value) { return strv_consume(l, v); } +int strv_extend_front(char ***l, const char *value) { + size_t n, m; + char *v, **c; + + assert(l); + + /* Like strv_extend(), but prepends rather than appends the new entry */ + + if (!value) + return 0; + + n = strv_length(*l); + + /* Increase and overflow check. */ + m = n + 2; + if (m < n) + return -ENOMEM; + + v = strdup(value); + if (!v) + return -ENOMEM; + + c = realloc_multiply(*l, sizeof(char*), m); + if (!c) { + free(v); + return -ENOMEM; + } + + memmove(c+1, c, n * sizeof(char*)); + c[0] = v; + c[n+1] = NULL; + + *l = c; + return 0; +} + char **strv_uniq(char **l) { char **i; |