summaryrefslogtreecommitdiff
path: root/src/basic/env-util.c
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2016-11-08 09:41:51 +0100
committerGitHub <noreply@github.com>2016-11-08 09:41:51 +0100
commitca91fd2acac007f0096fea47b2cc8931baa3af57 (patch)
tree4da5222881a4b3ec7e3b55dfa18fb8b7f764daa7 /src/basic/env-util.c
parented7fd549d0a1bfebe4e17a3f0e92879eb986d4a9 (diff)
parentbc8ec170d2bc3e294f24ff8bb255436a685ac14a (diff)
Merge pull request #4509 from keszybz/foreach-word-quoted
Remove FOREACH_WORD_QUOTED
Diffstat (limited to 'src/basic/env-util.c')
-rw-r--r--src/basic/env-util.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index b74290d6fd..7c69ccdaf9 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -384,6 +384,28 @@ char **strv_env_unset_many(char **l, ...) {
return l;
}
+int strv_env_replace(char ***l, char *p) {
+ char **f;
+
+ assert(p);
+
+ /* Replace first occurrence of the env var or add a new one in the
+ * string list. Drop other occurences. Edits in-place. Does not copy p.
+ */
+
+ for (f = *l; f && *f; f++)
+ if (env_match(*f, p)) {
+ free_and_replace(*f, p);
+ strv_env_unset(f + 1, p);
+ return 0;
+ }
+
+ /* We didn't find a match, we need to append p or create a new strv */
+ if (strv_push(l, p) < 0)
+ return -ENOMEM;
+ return 1;
+}
+
char **strv_env_set(char **x, const char *p) {
char **k, **r;