summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Betts <paul@paulbetts.org>2011-09-21 11:17:30 -0700
committerPaul Betts <paul@paulbetts.org>2011-09-21 12:00:34 -0700
commite1b86444676b70154bf8ab450d429bdef57a8276 (patch)
tree020b42f514cd78ddd44b4d38e0f57cd88f17616f /src
parente3ecf7e9ab043e44ffd94729f27e3a0c434c355a (diff)
downloadlibgit2-e1b86444676b70154bf8ab450d429bdef57a8276.tar.gz
Rewrite getenv to use Win32 version on Windows
Diffstat (limited to 'src')
-rw-r--r--src/config.c12
-rw-r--r--src/posix.c9
-rw-r--r--src/posix.h1
-rw-r--r--src/win32/posix_w32.c24
4 files changed, 42 insertions, 4 deletions
diff --git a/src/config.c b/src/config.c
index f233e76fd..261beb425 100644
--- a/src/config.c
+++ b/src/config.c
@@ -306,20 +306,24 @@ int git_config_get_string(git_config *cfg, const char *name, const char **out)
int git_config_find_global(char *global_config_path)
{
- const char *home;
+ char *home;
- home = getenv("HOME");
+ home = p_getenv("HOME");
#ifdef GIT_WIN32
if (home == NULL)
- home = getenv("USERPROFILE");
+ home = p_getenv("USERPROFILE");
#endif
- if (home == NULL)
+ if (home == NULL) {
+ free(home);
return git__throw(GIT_EOSERR, "Failed to open global config file. Cannot locate the user's home directory");
+ }
git_path_join(global_config_path, home, GIT_CONFIG_FILENAME);
+ free(home);
+
if (git_futils_exists(global_config_path) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to open global config file. The file does not exist");
diff --git a/src/posix.c b/src/posix.c
index 1b85b053d..fb8ce37cb 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -39,6 +39,15 @@ int p_getcwd(char *buffer_out, size_t size)
return GIT_SUCCESS;
}
+char* p_getenv(const char* name)
+{
+ char* buf = getenv(name);
+ if (!buf)
+ return buf;
+
+ return git__strdup(buf);
+}
+
#endif
int p_read(git_file fd, void *buf, size_t cnt)
diff --git a/src/posix.h b/src/posix.h
index 48b0255bc..d656e8ec0 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -44,6 +44,7 @@ extern int p_write(git_file fd, const void *buf, size_t cnt);
extern int p_open(const char *path, int flags);
extern int p_creat(const char *path, int mode);
extern int p_getcwd(char *buffer_out, size_t size);
+extern char* p_getenv(const char* name);
#ifndef GIT_WIN32
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index af54e7f82..85a04bc0f 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -370,6 +370,30 @@ int p_mkstemp(char *tmp_path)
return p_creat(tmp_path, 0744);
}
+char* p_getenv(const char* name)
+{
+ wchar_t* buf;
+ wchar_t* name_w = conv_utf8_to_utf16(name);
+ char* ret;
+ DWORD len;
+
+ len = GetEnvironmentVariableW(name_w, NULL, 0);
+ if (len == 0) {
+ free(name_w);
+ return NULL;
+ }
+
+ len++; /* Null Terminator */
+ buf = malloc(sizeof(wchar_t) * len);
+ GetEnvironmentVariableW(name_w, buf, len);
+
+ ret = conv_utf16_to_utf8(buf);
+
+ free(name_w);
+ free(buf);
+ return ret;
+}
+
int p_setenv(const char* name, const char* value, int overwrite)
{
if (overwrite != 1)