aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-08-09 17:28:31 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-08-09 17:29:42 +0200
commitf94550ec61b33a9c26e5d6ecb9d36a99556f45d9 (patch)
tree1df5640ca9f4c622e1358ae24ced9c2732158895
parent69d45fea44dcf289a997c2df1d813ba355af743d (diff)
downloadfiv-f94550ec61b33a9c26e5d6ecb9d36a99556f45d9.tar.gz
fiv-f94550ec61b33a9c26e5d6ecb9d36a99556f45d9.tar.xz
fiv-f94550ec61b33a9c26e5d6ecb9d36a99556f45d9.zip
Improve XDG path handling on Windows
-rw-r--r--xdg.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/xdg.c b/xdg.c
index d412f61..aeb8073 100644
--- a/xdg.c
+++ b/xdg.c
@@ -48,20 +48,31 @@ get_xdg_home_dir(const char *var, const char *default_)
if (env && g_path_is_absolute(env))
return g_strdup(env);
+#ifdef G_OS_WIN32
+ return g_build_filename(g_get_home_dir(), default_, NULL);
+#else
// The specification doesn't handle a missing HOME variable explicitly.
// Implicitly, assuming Bourne shell semantics, it simply resolves empty.
const char *home = getenv("HOME");
return g_build_filename(home ? home : "", default_, NULL);
+#endif
}
+// Reïmplemented partly due to https://gitlab.gnome.org/GNOME/glib/-/issues/2501
static gchar **
get_xdg_data_dirs(void)
{
// GStrvBuilder is too new, it would help a little bit.
GPtrArray *output = g_ptr_array_new_with_free_func(g_free);
+
+#ifdef G_OS_WIN32
+ g_ptr_array_add(output, g_strdup(g_get_user_data_dir()));
+ for (const gchar *const *p = g_get_system_data_dirs(); *p; p++)
+ g_ptr_array_add(output, g_strdup(*p));
+#else
g_ptr_array_add(output, get_xdg_home_dir("XDG_DATA_HOME", ".local/share"));
- const char *xdg_data_dirs;
+ const char *xdg_data_dirs = "";
if (!(xdg_data_dirs = getenv("XDG_DATA_DIRS")) || !*xdg_data_dirs)
xdg_data_dirs = "/usr/local/share/:/usr/share/";
@@ -73,6 +84,7 @@ get_xdg_data_dirs(void)
g_free(*p);
}
g_free(candidates);
+#endif
g_ptr_array_add(output, NULL);
return (gchar **) g_ptr_array_free(output, FALSE);
}