Description: Handle the G_HOME environment variable to override the passwd entry This will allow to fix various kinds of build failures due to restricted build environments. Author: Josselin Mouette Origin: vendor --- a/docs/reference/glib/running.sgml +++ b/docs/reference/glib/running.sgml @@ -213,6 +213,22 @@ + + <envar>G_HOME</envar> + + + For various reasons, GLib applications ignore the HOME + environment variable on Unix systems and will use the user directory + as specified by the passwd entry, which is more + reliable. + + + The G_HOME environment variable will override any + other setting for the home directory. It is not meant for daily usage, + but it is useful in testing or building environments. + + + --- a/glib/gutils.c +++ b/glib/gutils.c @@ -1626,11 +1626,14 @@ } #endif /* !G_OS_WIN32 */ + g_home_dir = g_strdup (g_getenv ("G_HOME")); + #ifdef G_OS_WIN32 /* We check $HOME first for Win32, though it is a last resort for Unix * where we prefer the results of getpwuid(). */ - g_home_dir = g_strdup (g_getenv ("HOME")); + if (!g_home_dir) + g_home_dir = g_strdup (g_getenv ("HOME")); /* Only believe HOME if it is an absolute path and exists */ if (g_home_dir) @@ -1926,6 +1929,11 @@ * homedir = g_get_home_dir (); * ]| * + * However, to allow changing this value for testing and development + * purposes, the value of the G_HOME environment + * variable, if set, will override the passwd + * entry. + * * Returns: the current user's home directory */ G_CONST_RETURN gchar*