diff options
Diffstat (limited to 'shared/systemd/src/basic/strv.c')
| -rw-r--r-- | shared/systemd/src/basic/strv.c | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/shared/systemd/src/basic/strv.c b/shared/systemd/src/basic/strv.c index 30d3af46..7d3e3fc7 100644 --- a/shared/systemd/src/basic/strv.c +++ b/shared/systemd/src/basic/strv.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "nm-sd-adapt-shared.h" @@ -125,7 +125,6 @@ size_t strv_length(char * const *l) { } char **strv_new_ap(const char *x, va_list ap) { - const char *s; _cleanup_strv_free_ char **a = NULL; size_t n = 0, i = 0; va_list aq; @@ -135,43 +134,28 @@ char **strv_new_ap(const char *x, va_list ap) { * STRV_IFNOTNULL() macro to include possibly NULL strings in * the string list. */ - if (x) { - n = x == STRV_IGNORE ? 0 : 1; - - va_copy(aq, ap); - while ((s = va_arg(aq, const char*))) { - if (s == STRV_IGNORE) - continue; - - n++; - } + va_copy(aq, ap); + for (const char *s = x; s; s = va_arg(aq, const char*)) { + if (s == STRV_IGNORE) + continue; - va_end(aq); + n++; } + va_end(aq); a = new(char*, n+1); if (!a) return NULL; - if (x) { - if (x != STRV_IGNORE) { - a[i] = strdup(x); - if (!a[i]) - return NULL; - i++; - } - - while ((s = va_arg(ap, const char*))) { - - if (s == STRV_IGNORE) - continue; + for (const char *s = x; s; s = va_arg(ap, const char*)) { + if (s == STRV_IGNORE) + continue; - a[i] = strdup(s); - if (!a[i]) - return NULL; + a[i] = strdup(s); + if (!a[i]) + return NULL; - i++; - } + i++; } a[i] = NULL; @@ -543,6 +527,19 @@ int strv_consume_prepend(char ***l, char *value) { return r; } +int strv_prepend(char ***l, const char *value) { + char *v; + + if (!value) + return 0; + + v = strdup(value); + if (!v) + return -ENOMEM; + + return strv_consume_prepend(l, v); +} + int strv_extend(char ***l, const char *value) { char *v; |