summaryrefslogtreecommitdiffstats
path: root/src/basic/env-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-03-27 11:21:06 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-03-27 19:51:54 +0200
commit409759634e7fefc8120fca3f69b1a9aa0a68f396 (patch)
treeb08ee9780c040e7d21656d0dc6e18faeb8854786 /src/basic/env-util.c
parentukify: Weaken file alignment assertions (diff)
downloadsystemd-409759634e7fefc8120fca3f69b1a9aa0a68f396.tar.xz
systemd-409759634e7fefc8120fca3f69b1a9aa0a68f396.zip
env-util: introduce strv_env_assign_many()
Diffstat (limited to 'src/basic/env-util.c')
-rw-r--r--src/basic/env-util.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index 55ac11a512..41fad1d1b9 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -459,6 +459,48 @@ int strv_env_assign(char ***l, const char *key, const char *value) {
return strv_env_replace_consume(l, p);
}
+int _strv_env_assign_many(char ***l, ...) {
+ va_list ap;
+ int r;
+
+ assert(l);
+
+ va_start(ap, l);
+ for (;;) {
+ const char *key, *value;
+
+ key = va_arg(ap, const char *);
+ if (!key)
+ break;
+
+ if (!env_name_is_valid(key)) {
+ va_end(ap);
+ return -EINVAL;
+ }
+
+ value = va_arg(ap, const char *);
+ if (!value) {
+ strv_env_unset(*l, key);
+ continue;
+ }
+
+ char *p = strjoin(key, "=", value);
+ if (!p) {
+ va_end(ap);
+ return -ENOMEM;
+ }
+
+ r = strv_env_replace_consume(l, p);
+ if (r < 0) {
+ va_end(ap);
+ return r;
+ }
+ }
+ va_end(ap);
+
+ return 0;
+}
+
char *strv_env_get_n(char **l, const char *name, size_t k, unsigned flags) {
assert(name);