diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-04-10 17:43:12 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-04-10 18:00:33 +0200 |
commit | 257eca1a9c2d0ef110c21e74952e9723d778e267 (patch) | |
tree | 4f35626a2d5be2bacef866a04b3a2d0b38354bd1 | |
parent | dad08730c43807c5b9f9aa3f164c31997e66eea3 (diff) |
strv: introduce strv_new_ap() call
-rw-r--r-- | strv.c | 30 | ||||
-rw-r--r-- | strv.h | 1 |
2 files changed, 20 insertions, 11 deletions
@@ -85,21 +85,20 @@ unsigned strv_length(char **l) { return n; } -char **strv_new(const char *x, ...) { +char **strv_new_ap(const char *x, va_list ap) { const char *s; char **a; unsigned n = 0, i = 0; - va_list ap; + va_list aq; + if (x) { n = 1; - va_start(ap, x); - - while (va_arg(ap, const char*)) + va_copy(aq, ap); + while (va_arg(aq, const char*)) n++; - - va_end(ap); + va_end(aq); } if (!(a = new(char*, n+1))) @@ -113,19 +112,16 @@ char **strv_new(const char *x, ...) { i++; - va_start(ap, x); - while ((s = va_arg(ap, const char*))) { if (!(a[i] = strdup(s))) goto fail; i++; } - - va_end(ap); } a[i] = NULL; + return a; fail: @@ -135,9 +131,21 @@ fail: free(a[i-1]); free(a); + return NULL; } +char **strv_new(const char *x, ...) { + char **r; + va_list ap; + + va_start(ap, x); + r = strv_new_ap(x, ap); + va_end(ap); + + return r; +} + char **strv_merge(char **a, char **b) { char **r, **k; @@ -39,6 +39,7 @@ char **strv_uniq(char **l); #define strv_contains(l, s) (!!strv_find((l), (s))) char **strv_new(const char *x, ...) _sentinel; +char **strv_new_ap(const char *x, va_list ap); static inline bool strv_isempty(char **l) { return !l || !*l; |