path.c: implement xdg_config_home()
[gitweb.git] / path.c
diff --git a/path.c b/path.c
index e6089938018b74fb8a6ea547ffc64d428a13daa0..4edc1eb8680a63a6eff8c3a910748d195565a32b 100644 (file)
--- a/path.c
+++ b/path.c
@@ -856,3 +856,18 @@ int is_ntfs_dotgit(const char *name)
                        len = -1;
                }
 }
+
+char *xdg_config_home(const char *filename)
+{
+       const char *home, *config_home;
+
+       assert(filename);
+       config_home = getenv("XDG_CONFIG_HOME");
+       if (config_home && *config_home)
+               return mkpathdup("%s/git/%s", config_home, filename);
+
+       home = getenv("HOME");
+       if (home)
+               return mkpathdup("%s/.config/git/%s", home, filename);
+       return NULL;
+}