From 254ff898f6941651d1e7a921ad9f979c01551d5f Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Fri, 3 Sep 2010 17:49:53 +0000 Subject: [PATCH] cleanup of setenvf function --- src/common/env.c | 30 ++++++++---------------------- src/common/env.h | 11 +++++++---- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/common/env.c b/src/common/env.c index 2847a85a3a8..f208e39d4d7 100644 --- a/src/common/env.c +++ b/src/common/env.c @@ -282,39 +282,25 @@ setenvfs(const char *fmt, ...) return rc; } -int -setenvf(char ***envp, const char *name, const char *fmt, ...) +int setenvf(char ***envp, const char *name, const char *fmt, ...) { - char **ep = NULL; - char *str = NULL; + char *str = NULL, *value; va_list ap; int rc; - char *buf, *bufcpy; - buf = xmalloc(ENV_BUFSIZE); + value = xmalloc(ENV_BUFSIZE); va_start(ap, fmt); - vsnprintf (buf, ENV_BUFSIZE, fmt, ap); + vsnprintf (value, ENV_BUFSIZE, fmt, ap); va_end(ap); - bufcpy = xstrdup(buf); - xfree(buf); - xstrfmtcat (str, "%s=%s", name, bufcpy); - xfree(bufcpy); if (envp && *envp) { - ep = _find_name_in_env (*envp, name); - - if (*ep != NULL) - xfree (*ep); - else - ep = _extend_env (envp); - - *ep = str; - - return (0); + rc = env_array_overwrite(envp, name, value); } else { + xstrfmtcat(str, "%s=%s", name, value); rc = putenv(str); - return rc; } + xfree(value); + return rc; } /* diff --git a/src/common/env.h b/src/common/env.h index b8795e2de25..e39f791ae19 100644 --- a/src/common/env.h +++ b/src/common/env.h @@ -79,11 +79,14 @@ typedef struct env_options { } env_t; -int envcount (char **env); -int setenvfs(const char *fmt, ...); -int setenvf(char ***envp, const char *name, const char *fmt, ...); -void unsetenvp(char **env, const char *name); +/* NOTE: These functions operate on the job's current environment + * if env is NULL, otherwise they operate on the argument array */ +int envcount (char **env); char * getenvp(char **env, const char *name); +int setenvf(char ***envp, const char *name, const char *fmt, ...); +int setenvfs(const char *fmt, ...); +void unsetenvp(char **env, const char *name); + int setup_env(env_t *env, bool preserve_env); /********************************************************************** -- GitLab