diff options
-rw-r--r-- | compat/mingw.c | 16 | ||||
-rw-r--r-- | compat/mingw.h | 3 | ||||
-rw-r--r-- | run-command.c | 7 |
3 files changed, 17 insertions, 9 deletions
diff --git a/compat/mingw.c b/compat/mingw.c index bed417875..36ef8d321 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -824,7 +824,7 @@ void mingw_execvp(const char *cmd, char *const *argv) free_path_split(path); } -char **copy_environ() +static char **copy_environ(void) { char **env; int i = 0; @@ -861,7 +861,7 @@ static int lookup_env(char **env, const char *name, size_t nmln) /* * If name contains '=', then sets the variable, otherwise it unsets it */ -char **env_setenv(char **env, const char *name) +static char **env_setenv(char **env, const char *name) { char *eq = strchrnul(name, '='); int i = lookup_env(env, name, eq-name); @@ -886,6 +886,18 @@ char **env_setenv(char **env, const char *name) return env; } +/* + * Copies global environ and adjusts variables as specified by vars. + */ +char **make_augmented_environ(const char *const *vars) +{ + char **env = copy_environ(); + + while (*vars) + env = env_setenv(env, *vars++); + return env; +} + /* this is the first function to call into WS_32; initialize it */ #undef gethostbyname struct hostent *mingw_gethostbyname(const char *host) diff --git a/compat/mingw.h b/compat/mingw.h index 948de66eb..c43917cd6 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -222,9 +222,8 @@ void mingw_open_html(const char *path); * helpers */ -char **copy_environ(void); +char **make_augmented_environ(const char *const *vars); void free_environ(char **env); -char **env_setenv(char **env, const char *name); /* * A replacement of main() that ensures that argv[0] has a path diff --git a/run-command.c b/run-command.c index f3e7abb7d..ac314a5a8 100644 --- a/run-command.c +++ b/run-command.c @@ -173,11 +173,8 @@ fail_pipe: if (cmd->dir) die("chdir in start_command() not implemented"); - if (cmd->env) { - env = copy_environ(); - for (; *cmd->env; cmd->env++) - env = env_setenv(env, *cmd->env); - } + if (cmd->env) + env = make_augmented_environ(cmd->env); if (cmd->git_cmd) { cmd->argv = prepare_git_cmd(cmd->argv); |