summaryrefslogtreecommitdiffstats
path: root/src/basic/env-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-02-15 14:09:30 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-02-15 20:43:41 +0100
commitaaf057c4bbc6055040d7d2c1ec3655ff89249ebd (patch)
tree7981275d953245cf8908b64bd753d3bcd13c5da4 /src/basic/env-util.c
parentci: switch back to meson-0.56.2 (diff)
downloadsystemd-aaf057c4bbc6055040d7d2c1ec3655ff89249ebd.tar.xz
systemd-aaf057c4bbc6055040d7d2c1ec3655ff89249ebd.zip
basic/env-util: add variant of strv_env_replace() that does strdup internally
Diffstat (limited to 'src/basic/env-util.c')
-rw-r--r--src/basic/env-util.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index a75186015e..5335c6784d 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -370,9 +370,8 @@ int strv_env_replace(char ***l, char *p) {
assert(p);
- /* Replace first occurrence of the env var or add a new one in the string list. Drop other occurrences. Edits
- * in-place. Does not copy p. p must be a valid key=value assignment.
- */
+ /* Replace first occurrence of the env var or add a new one in the string list. Drop other
+ * occurrences. Edits in-place. Does not copy p. p must be a valid key=value assignment. */
t = strchr(p, '=');
if (!t)
@@ -395,6 +394,23 @@ int strv_env_replace(char ***l, char *p) {
return 1;
}
+int strv_env_replace_strdup(char ***l, const char *assignment) {
+ int r;
+
+ /* Like strv_env_replace(), but copies the argument. */
+
+ _cleanup_free_ char *p = strdup(assignment);
+ if (!p)
+ return -ENOMEM;
+
+ r = strv_env_replace(l, p);
+ if (r < 0)
+ return r;
+
+ TAKE_PTR(p);
+ return r;
+}
+
char **strv_env_set(char **x, const char *p) {
_cleanup_strv_free_ char **ret = NULL;
size_t n, m;