summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-06-18 01:50:48 +0200
committerVicent Marti <tanoku@gmail.com>2011-06-18 01:50:48 +0200
commit19cb6857a4fcdc6df5cc6385d94d66d3962b237d (patch)
treed9ed263edb838e9dcd7abbcdd9da91bbf2ce9de1 /src
parent920e000d38c5514499a5f0236fdfe11f3b14d9b1 (diff)
downloadlibgit2-19cb6857a4fcdc6df5cc6385d94d66d3962b237d.tar.gz
config: Bring back `git_config_open_global`
Scott commands, I obey.
Diffstat (limited to 'src')
-rw-r--r--src/config.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
index b802ba50b..cc31bda6d 100644
--- a/src/config.c
+++ b/src/config.c
@@ -319,3 +319,36 @@ int git_config_get_string(git_config *cfg, const char *name, const char **out)
return git__throw(error, "Config value '%s' not found", name);
}
+int git_config_find_global(char *global_config_path)
+{
+ const char *home;
+
+ home = getenv("HOME");
+
+#ifdef GIT_WIN32
+ if (home == NULL)
+ home = getenv("USERPROFILE");
+#endif
+
+ if (home == NULL)
+ return git__throw(GIT_EOSERR, "Failed to open global config file. Cannot locate the user's home directory");
+
+ git__joinpath(global_config_path, home, GIT_CONFIG_FILENAME);
+
+ if (gitfo_exists(global_config_path) < GIT_SUCCESS)
+ return git__throw(GIT_EOSERR, "Failed to open global config file. The file does not exist");
+
+ return GIT_SUCCESS;
+}
+
+int git_config_open_global(git_config **out)
+{
+ int error;
+ char global_path[GIT_PATH_MAX];
+
+ if ((error = git_config_find_global(global_path)) < GIT_SUCCESS)
+ return error;
+
+ return git_config_open_ondisk(out, global_path);
+}
+