basic/env-util: add putenv_dup()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-02-22 20:10:55 +01:00
parent f70e6fb471
commit fa256f43e7
3 changed files with 32 additions and 0 deletions
+15
View File
@@ -768,6 +768,21 @@ int set_unset_env(const char *name, const char *value, bool overwrite) {
return 0;
}
int putenv_dup(const char *assignment, bool override) {
const char *e, *n;
e = strchr(assignment, '=');
if (!e)
return -EINVAL;
n = strndupa(assignment, e - assignment);
/* This is like putenv(), but uses setenv() so that our memory doesn't become part of environ[]. */
if (setenv(n, e + 1, override) < 0)
return -errno;
return 0;
}
int setenv_systemd_exec_pid(bool update_only) {
char str[DECIMAL_STR_MAX(pid_t)];
const char *e;