summaryrefslogtreecommitdiff
path: root/src/libgit2/sysdir.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-01-22 15:23:10 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2023-02-09 12:10:40 +0000
commitbce17198f561ed85c0788adc8f0a3259a18a545d (patch)
treeac7a3c203188d1d2aba66d6ea3371fe278641a77 /src/libgit2/sysdir.c
parent9a9863645de0c750525a4119bbd3534e231d7360 (diff)
downloadlibgit2-bce17198f561ed85c0788adc8f0a3259a18a545d.tar.gz
sysdir: provide actual home directory
Provide a mechanism to look up the user's home directory, using the same mechanism that we use for locating the global configuration path (a fancy name for saying "the home directory"). SSH known hosts lookups now use this, instead of simply looking at the HOME environment variable, to support Windows-style home directory lookups in `HOME`, `HOMEPATH`, or `USERPROFILE`.
Diffstat (limited to 'src/libgit2/sysdir.c')
-rw-r--r--src/libgit2/sysdir.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/libgit2/sysdir.c b/src/libgit2/sysdir.c
index 8456f47a9..7838a6789 100644
--- a/src/libgit2/sysdir.c
+++ b/src/libgit2/sysdir.c
@@ -321,7 +321,7 @@ out:
}
#endif
-static int git_sysdir_guess_global_dirs(git_str *out)
+static int git_sysdir_guess_home_dirs(git_str *out)
{
#ifdef GIT_WIN32
static const wchar_t *global_tmpls[4] = {
@@ -367,6 +367,11 @@ static int git_sysdir_guess_global_dirs(git_str *out)
#endif
}
+static int git_sysdir_guess_global_dirs(git_str *out)
+{
+ return git_sysdir_guess_home_dirs(out);
+}
+
static int git_sysdir_guess_xdg_dirs(git_str *out)
{
#ifdef GIT_WIN32
@@ -434,6 +439,7 @@ static struct git_sysdir__dir git_sysdir__dirs[] = {
{ GIT_STR_INIT, git_sysdir_guess_xdg_dirs },
{ GIT_STR_INIT, git_sysdir_guess_programdata_dirs },
{ GIT_STR_INIT, git_sysdir_guess_template_dirs },
+ { GIT_STR_INIT, git_sysdir_guess_home_dirs }
};
static void git_sysdir_global_shutdown(void)
@@ -613,6 +619,12 @@ int git_sysdir_find_template_dir(git_str *path)
path, NULL, GIT_SYSDIR_TEMPLATE, "template");
}
+int git_sysdir_find_homedir(git_str *path)
+{
+ return git_sysdir_find_in_dirlist(
+ path, NULL, GIT_SYSDIR_HOME, "home directory");
+}
+
int git_sysdir_expand_global_file(git_str *path, const char *filename)
{
int error;
@@ -624,3 +636,15 @@ int git_sysdir_expand_global_file(git_str *path, const char *filename)
return error;
}
+
+int git_sysdir_expand_homedir_file(git_str *path, const char *filename)
+{
+ int error;
+
+ if ((error = git_sysdir_find_homedir(path)) == 0) {
+ if (filename)
+ error = git_str_joinpath(path, path->ptr, filename);
+ }
+
+ return error;
+}