summaryrefslogtreecommitdiff
path: root/src/sysdir.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-07-07 00:48:17 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-07-07 00:48:17 +0200
commitea445e06028a1192e7e948cc81c87c4b39bc446e (patch)
treebd1da56716d690f60c3a3e8d97f3902c41aac5cb /src/sysdir.c
parent3c831113ca134b86f52fbc96e5988471f1cace11 (diff)
parente069c621bdd62e603b048eb536f5a978a905b310 (diff)
downloadlibgit2-ea445e06028a1192e7e948cc81c87c4b39bc446e.tar.gz
Merge pull request #3288 from ethomson/getenv
git__getenv: utf-8 aware env reader
Diffstat (limited to 'src/sysdir.c')
-rw-r--r--src/sysdir.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/sysdir.c b/src/sysdir.c
index cd94a8b57..2795de491 100644
--- a/src/sysdir.c
+++ b/src/sysdir.c
@@ -29,7 +29,14 @@ static int git_sysdir_guess_global_dirs(git_buf *out)
#ifdef GIT_WIN32
return git_win32__find_global_dirs(out);
#else
- return git_buf_sets(out, getenv("HOME"));
+ int error = git__getenv(out, "HOME");
+
+ if (error == GIT_ENOTFOUND) {
+ giterr_clear();
+ error = 0;
+ }
+
+ return error;
#endif
}
@@ -38,15 +45,22 @@ static int git_sysdir_guess_xdg_dirs(git_buf *out)
#ifdef GIT_WIN32
return git_win32__find_xdg_dirs(out);
#else
- const char *env = NULL;
+ git_buf env = GIT_BUF_INIT;
+ int error;
- if ((env = getenv("XDG_CONFIG_HOME")) != NULL)
- return git_buf_joinpath(out, env, "git");
- else if ((env = getenv("HOME")) != NULL)
- return git_buf_joinpath(out, env, ".config/git");
+ if ((error = git__getenv(&env, "XDG_CONFIG_HOME")) == 0)
+ error = git_buf_joinpath(out, env.ptr, "git");
- git_buf_clear(out);
- return 0;
+ if (error == GIT_ENOTFOUND && (error = git__getenv(&env, "HOME")) == 0)
+ error = git_buf_joinpath(out, env.ptr, ".config/git");
+
+ if (error == GIT_ENOTFOUND) {
+ giterr_clear();
+ error = 0;
+ }
+
+ git_buf_free(&env);
+ return error;
#endif
}