From: Jonas Fonseca Date: Tue, 10 Feb 2009 10:50:59 +0000 (+0100) Subject: Use putenv instead of setenv X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=46ef80d6e6650ae5d39dbd308ccf893cba20e57a;p=tig.git Use putenv instead of setenv Not all platforms (e.g. Solaris) provide setenv. Based on patch by SungHyun Nam. --- diff --git a/tig.c b/tig.c index aec50bc..a0d4df4 100644 --- a/tig.c +++ b/tig.c @@ -6727,6 +6727,20 @@ set_repo_config_option(char *name, char *value, int (*cmd)(int, const char **)) warn("Option 'tig.%s': %s", name, config_msg); } +static bool +set_environment_variable(const char *name, const char *value) +{ + size_t len = strlen(name) + 1 + strlen(value) + 1; + char *env = malloc(len); + + if (env && + string_nformat(env, len, NULL, "%s=%s", name, value) && + putenv(env) == 0) + return TRUE; + free(env); + return FALSE; +} + static void set_work_tree(const char *value) { @@ -6744,9 +6758,9 @@ set_work_tree(const char *value) die("Failed to chdir(%s): %s", value, strerror(errno)); if (!getcwd(cwd, sizeof(cwd))) die("Failed to get cwd path: %s", strerror(errno)); - if (setenv("GIT_WORK_TREE", cwd, TRUE) < 0) + if (!set_environment_variable("GIT_WORK_TREE", cwd)) die("Failed to set GIT_WORK_TREE to '%s'", cwd); - if (setenv("GIT_DIR", opt_git_dir, TRUE) < 0) + if (!set_environment_variable("GIT_DIR", opt_git_dir)) die("Failed to set GIT_DIR to '%s'", opt_git_dir); opt_is_inside_work_tree = TRUE; }