summaryrefslogtreecommitdiff
path: root/src/basic/env-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-08-07 10:16:19 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-08-11 09:11:42 +0200
commit4ab3d29ff03c0508f47846875d9310cbc5b8cd0f (patch)
treea4b268f1d168b9c5b6587343142de20f4bf6116c /src/basic/env-util.c
parentd340bdd1bd435e9f5524f4246feaf38511b2ff45 (diff)
downloadsystemd-4ab3d29ff03c0508f47846875d9310cbc5b8cd0f.tar.gz
Add implicit sentinel to strv_env_merge()
Just to make it a tiny bit nicer to use.
Diffstat (limited to 'src/basic/env-util.c')
-rw-r--r--src/basic/env-util.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index 81b1e3f10e..0c30ddc277 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -183,39 +183,51 @@ static int env_append(char **r, char ***k, char **a) {
return 0;
}
-char **strv_env_merge(size_t n_lists, ...) {
- _cleanup_strv_free_ char **ret = NULL;
- size_t n = 0;
- char **l, **k;
+char** _strv_env_merge(char **first, ...) {
+ _cleanup_strv_free_ char **merged = NULL;
+ char **k;
va_list ap;
/* Merges an arbitrary number of environment sets */
- va_start(ap, n_lists);
- for (size_t i = 0; i < n_lists; i++) {
+ size_t n = strv_length(first);
+
+ va_start(ap, first);
+ for (;;) {
+ char **l;
+
l = va_arg(ap, char**);
+ if (l == POINTER_MAX)
+ break;
+
n += strv_length(l);
}
va_end(ap);
- ret = new(char*, n+1);
- if (!ret)
+ k = merged = new(char*, n + 1);
+ if (!merged)
return NULL;
+ merged[0] = NULL;
- *ret = NULL;
- k = ret;
+ if (env_append(merged, &k, first) < 0)
+ return NULL;
+
+ va_start(ap, first);
+ for (;;) {
+ char **l;
- va_start(ap, n_lists);
- for (size_t i = 0; i < n_lists; i++) {
l = va_arg(ap, char**);
- if (env_append(ret, &k, l) < 0) {
+ if (l == POINTER_MAX)
+ break;
+
+ if (env_append(merged, &k, l) < 0) {
va_end(ap);
return NULL;
}
}
va_end(ap);
- return TAKE_PTR(ret);
+ return TAKE_PTR(merged);
}
static bool env_match(const char *t, const char *pattern) {