summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2011-05-19 14:18:57 -0700
committerVicent Martí <tanoku@gmail.com>2011-05-19 14:18:57 -0700
commit274f2c213fdb2402b586827e6e6e27b2e055101c (patch)
treedb8c6b14f74d9518ad7694b6bc9c67f26d7e6c5d /src/config.c
parent44d16d6fb2987d4025714214139b22fc1a2ccfe1 (diff)
parent6421c49a3726b4132aafcc780016f5a984832caf (diff)
downloadlibgit2-274f2c213fdb2402b586827e6e6e27b2e055101c.tar.gz
Merge pull request #193 from carlosmn/config
A couple of config improvements
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
index cd0a73ccd..0ade5cf97 100644
--- a/src/config.c
+++ b/src/config.c
@@ -70,6 +70,40 @@ int git_config_open_bare(git_config **out, const char *path)
return error;
}
+int git_config_open_global(git_config **out)
+{
+ char *home = NULL, *filename = NULL;
+ const char *gitconfig = ".gitconfig";
+ int filename_len, ret, error;
+
+ home = git__strdup(getenv("HOME"));
+ if (home == NULL)
+ return GIT_ENOMEM;
+
+ filename_len = strlen(home) + strlen(gitconfig) + 1;
+ filename = git__malloc(filename_len + 1);
+ if (filename == NULL) {
+ error = GIT_ENOMEM;
+ goto out;
+ }
+
+ ret = snprintf(filename, filename_len, "%s/%s", home, gitconfig);
+ if (ret < 0) {
+ error = git__throw(GIT_EOSERR, "Failed to build global filename. OS err: %s", strerror(errno));
+ goto out;
+ } else if (ret >= filename_len) {
+ error = git__throw(GIT_ERROR, "Failed to build global filename. Length calulation wrong");
+ goto out;
+ }
+
+ error = git_config_open_bare(out, filename);
+
+ out:
+ free(home);
+ free(filename);
+ return error;
+}
+
void git_config_free(git_config *cfg)
{
unsigned int i;