gutils: Refactor g_get_home_dir() to use a global variable

While this might seem like a regression, it means that the home
directory can be overridden by GLib internal code, which will be done in
an upcoming commit. This brings g_get_home_dir() inline with functions
like g_get_user_data_dir().

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://gitlab.gnome.org/GNOME/glib/issues/538
This commit is contained in:
Philip Withnall 2018-11-30 17:29:56 +00:00
parent 2c8ae9f175
commit 8da50ac40c

View File

@ -791,6 +791,9 @@ g_get_real_name (void)
return entry->real_name;
}
/* Protected by @g_utils_global_lock. */
static gchar *g_home_dir = NULL; /* (owned) (nullable before initialised) */
/**
* g_get_home_dir:
*
@ -820,9 +823,9 @@ g_get_real_name (void)
const gchar *
g_get_home_dir (void)
{
static gchar *home_dir;
G_LOCK (g_utils_global);
if (g_once_init_enter (&home_dir))
if (g_home_dir == NULL)
{
gchar *tmp;
@ -899,10 +902,12 @@ g_get_home_dir (void)
tmp = "/";
}
g_once_init_leave (&home_dir, tmp);
g_home_dir = g_steal_pointer (&tmp);
}
return home_dir;
G_UNLOCK (g_utils_global);
return g_home_dir;
}
/**