mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-28 12:53:30 +02:00
gutils: split out g_get_host_name()
Remove the code for getting the hostname from g_get_any_init_do() and outside of the g_utils_global lock.
This commit is contained in:
@@ -581,7 +581,6 @@ static gchar *g_tmp_dir = NULL;
|
|||||||
static gchar *g_user_name = NULL;
|
static gchar *g_user_name = NULL;
|
||||||
static gchar *g_real_name = NULL;
|
static gchar *g_real_name = NULL;
|
||||||
static gchar *g_home_dir = NULL;
|
static gchar *g_home_dir = NULL;
|
||||||
static gchar *g_host_name = NULL;
|
|
||||||
|
|
||||||
static gchar *g_user_data_dir = NULL;
|
static gchar *g_user_data_dir = NULL;
|
||||||
static gchar **g_system_data_dirs = NULL;
|
static gchar **g_system_data_dirs = NULL;
|
||||||
@@ -648,8 +647,6 @@ get_windows_directory_root (void)
|
|||||||
static void
|
static void
|
||||||
g_get_any_init_do (void)
|
g_get_any_init_do (void)
|
||||||
{
|
{
|
||||||
gchar hostname[100];
|
|
||||||
|
|
||||||
g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
|
g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
|
||||||
|
|
||||||
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
|
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
|
||||||
@@ -879,16 +876,6 @@ g_get_any_init_do (void)
|
|||||||
if (!g_real_name)
|
if (!g_real_name)
|
||||||
g_real_name = g_strdup ("Unknown");
|
g_real_name = g_strdup ("Unknown");
|
||||||
|
|
||||||
{
|
|
||||||
#ifndef G_OS_WIN32
|
|
||||||
gboolean hostname_fail = (gethostname (hostname, sizeof (hostname)) == -1);
|
|
||||||
#else
|
|
||||||
DWORD size = sizeof (hostname);
|
|
||||||
gboolean hostname_fail = (!GetComputerName (hostname, &size));
|
|
||||||
#endif
|
|
||||||
g_host_name = g_strdup (hostname_fail ? "localhost" : hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
g_tmp_dir_cp = g_locale_from_utf8 (g_tmp_dir, -1, NULL, NULL, NULL);
|
g_tmp_dir_cp = g_locale_from_utf8 (g_tmp_dir, -1, NULL, NULL, NULL);
|
||||||
g_user_name_cp = g_locale_from_utf8 (g_user_name, -1, NULL, NULL, NULL);
|
g_user_name_cp = g_locale_from_utf8 (g_user_name, -1, NULL, NULL, NULL);
|
||||||
@@ -1042,8 +1029,24 @@ g_get_tmp_dir (void)
|
|||||||
const gchar *
|
const gchar *
|
||||||
g_get_host_name (void)
|
g_get_host_name (void)
|
||||||
{
|
{
|
||||||
g_get_any_init_locked ();
|
static gchar *hostname;
|
||||||
return g_host_name;
|
|
||||||
|
if (g_once_init_enter (&hostname))
|
||||||
|
{
|
||||||
|
gboolean failed;
|
||||||
|
gchar tmp[100];
|
||||||
|
|
||||||
|
#ifndef G_OS_WIN32
|
||||||
|
failed = (gethostname (tmp, sizeof (tmp)) == -1);
|
||||||
|
#else
|
||||||
|
DWORD size = sizeof (tmp);
|
||||||
|
failed = (!GetComputerName (tmp, &size));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
g_once_init_leave (&hostname, g_strdup (failed ? "localhost" : tmp));
|
||||||
|
}
|
||||||
|
|
||||||
|
return hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
G_LOCK_DEFINE_STATIC (g_prgname);
|
G_LOCK_DEFINE_STATIC (g_prgname);
|
||||||
|
Reference in New Issue
Block a user