Skip to content
Snippets Groups Projects
Commit bb8a3a0c authored by Christopher J. Morrone's avatar Christopher J. Morrone
Browse files

Split env_array_append into env_array_append and env_array_append_fmt.

parent a4d5d0b7
No related branches found
No related tags found
No related merge requests found
...@@ -907,10 +907,12 @@ char **env_array_create(void) ...@@ -907,10 +907,12 @@ char **env_array_create(void)
* if and only if a variable by that name does not already exist in the * if and only if a variable by that name does not already exist in the
* array. * array.
* *
* "value_fmt" supports printf-style formatting.
*
* Return 1 on success, and 0 on error. * Return 1 on success, and 0 on error.
*/ */
int env_array_append(char ***array_ptr, const char *name, int env_array_append_fmt(char ***array_ptr, const char *name,
const char *value_fmt, ...) const char *value_fmt, ...)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
char **ep = NULL; char **ep = NULL;
...@@ -942,12 +944,47 @@ int env_array_append(char ***array_ptr, const char *name, ...@@ -942,12 +944,47 @@ int env_array_append(char ***array_ptr, const char *name,
return 1; 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 * Append a single environment variable to an environment variable array
* if a variable by that name does not already exist. If a variable * 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 * by the same name is found in the array, it is overwritten with the
* new value. * new value.
* *
* "value_fmt" supports printf-style formatting.
*
* Return 1 on success, and 0 on error. * Return 1 on success, and 0 on error.
*/ */
int env_array_overwrite_fmt(char ***array_ptr, const char *name, int env_array_overwrite_fmt(char ***array_ptr, const char *name,
......
...@@ -188,7 +188,19 @@ void env_array_free(char **env_array); ...@@ -188,7 +188,19 @@ void env_array_free(char **env_array);
* Return 1 on success, and 0 on error. * Return 1 on success, and 0 on error.
*/ */
int env_array_append(char ***array_ptr, const char *name, 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 * Append a single environment variable to an environment variable array
...@@ -207,6 +219,8 @@ int env_array_overwrite(char ***array_ptr, const char *name, ...@@ -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 * 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. * 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. * Return 1 on success, and 0 on error.
*/ */
int env_array_overwrite_fmt(char ***array_ptr, const char *name, int env_array_overwrite_fmt(char ***array_ptr, const char *name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment