summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: deefc9e)
raw | patch | inline | side by side (parent: deefc9e)
author | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 10 Feb 2009 10:50:59 +0000 (11:50 +0100) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 10 Feb 2009 10:50:59 +0000 (11:50 +0100) |
Not all platforms (e.g. Solaris) provide setenv. Based on patch by
SungHyun Nam.
SungHyun Nam.
tig.c | patch | blob | history |
index aec50bca39ff98d3d8358789c6a70f676e2d5bfb..a0d4df405c850d0d205846b9597be79251c966eb 100644 (file)
--- 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)
{
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;
}