diff --git a/src/common/env.c b/src/common/env.c index aa9f80dd55ca7b585669fb578a08638b48a48993..ba84a3b8d51890a01e0fb0d72d75b7d8a7b80a2f 100644 --- a/src/common/env.c +++ b/src/common/env.c @@ -907,10 +907,12 @@ char **env_array_create(void) * if and only if a variable by that name does not already exist in the * array. * + * "value_fmt" supports printf-style formatting. + * * Return 1 on success, and 0 on error. */ -int env_array_append(char ***array_ptr, const char *name, - const char *value_fmt, ...) +int env_array_append_fmt(char ***array_ptr, const char *name, + const char *value_fmt, ...) { char buf[BUFSIZ]; char **ep = NULL; @@ -942,12 +944,47 @@ int env_array_append(char ***array_ptr, const char *name, return 1; } +/* + * Append a single environment variable to an environment variable array, + * if and only if a variable by that name does not already exist in the + * array. + * + * Return 1 on success, and 0 on error. + */ +int env_array_append(char ***array_ptr, const char *name, + const char *value) +{ + char **ep = NULL; + char *str = NULL; + + if (array_ptr == NULL) { + return 0; + } + + if (*array_ptr == NULL) { + *array_ptr = env_array_create(); + } + + ep = _find_name_in_env(*array_ptr, name); + if (*ep != NULL) { + return 0; + } + + xstrfmtcat (str, "%s=%s", name, value); + ep = _extend_env(array_ptr); + *ep = str; + + return 1; +} + /* * Append a single environment variable to an environment variable array * if a variable by that name does not already exist. If a variable * by the same name is found in the array, it is overwritten with the * new value. * + * "value_fmt" supports printf-style formatting. + * * Return 1 on success, and 0 on error. */ int env_array_overwrite_fmt(char ***array_ptr, const char *name, diff --git a/src/common/env.h b/src/common/env.h index 5d5f46d4bc2fdc3916ffb68372b4eb70088eb975..f84a7acaef0843b8e44aa08bd737a69b92d44f3a 100644 --- a/src/common/env.h +++ b/src/common/env.h @@ -188,7 +188,19 @@ void env_array_free(char **env_array); * Return 1 on success, and 0 on error. */ int env_array_append(char ***array_ptr, const char *name, - const char *value_fmt, ...); + const char *value); + +/* + * Append a single environment variable to an environment variable array, + * if and only if a variable by that name does not already exist in the + * array. + * + * "value_fmt" supports printf-style formatting. + * + * Return 1 on success, and 0 on error. + */ +int env_array_append_fmt(char ***array_ptr, const char *name, + const char *value_fmt, ...); /* * Append a single environment variable to an environment variable array @@ -207,6 +219,8 @@ int env_array_overwrite(char ***array_ptr, const char *name, * by the same name is found in the array, it is overwritten with the * new value. The "value_fmt" string may contain printf-style options. * + * "value_fmt" supports printf-style formatting. + * * Return 1 on success, and 0 on error. */ int env_array_overwrite_fmt(char ***array_ptr, const char *name,