summaryrefslogtreecommitdiffstats
path: root/src/basic/strv.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-11-04 09:22:15 +0100
committerGitHub <noreply@github.com>2020-11-04 09:22:15 +0100
commit24309e6683020db6b2bdcbed52e2307306202b63 (patch)
treed2e14e8497606b49fa42b978108528250dc89adc /src/basic/strv.c
parentfileio: beef up READ_FULL_FILE_CONNECT_SOCKET to allow setting sender socket ... (diff)
parentstrv.c: simplify strv_new_ap (diff)
downloadsystemd-24309e6683020db6b2bdcbed52e2307306202b63.tar.xz
systemd-24309e6683020db6b2bdcbed52e2307306202b63.zip
Merge pull request #17493 from Villemoes/va-arg-simplifications
Some vararg simplifications
Diffstat (limited to 'src/basic/strv.c')
-rw-r--r--src/basic/strv.c42
1 files changed, 13 insertions, 29 deletions
diff --git a/src/basic/strv.c b/src/basic/strv.c
index c5e6dd5f21..dd3a164879 100644
--- a/src/basic/strv.c
+++ b/src/basic/strv.c
@@ -123,7 +123,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;
@@ -133,43 +132,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;