Use GLib's portable version gethostname(): g_get_host_name()

Drop our own portability layer and use GLib's one instead (which
actually does exactly the same as our own).

Thanks to Matthew for spotting this.
This commit is contained in:
Colomban Wendling 2013-08-18 00:29:04 +02:00
parent 978fca130f
commit 82f82ed372
9 changed files with 3 additions and 39 deletions

View File

@ -46,7 +46,7 @@ AC_TYPE_SIZE_T
AC_STRUCT_TM
# Checks for library functions.
AC_CHECK_FUNCS([gethostname ftruncate fgetpos mkstemp strerror strstr])
AC_CHECK_FUNCS([ftruncate fgetpos mkstemp strerror strstr])
# autoscan end

View File

@ -873,11 +873,9 @@ static void load_dialog_prefs(GKeyFile *config)
template_prefs.version = utils_get_setting_string(config, PACKAGE, "pref_template_version", "1.0");
tmp_string2 = utils_get_hostname();
tmp_string = g_strdup_printf("%s@%s", g_get_user_name(), tmp_string2);
tmp_string = g_strdup_printf("%s@%s", g_get_user_name(), g_get_host_name());
template_prefs.mail = utils_get_setting_string(config, PACKAGE, "pref_template_mail", tmp_string);
g_free(tmp_string);
g_free(tmp_string2);
template_prefs.year_format = utils_get_setting_string(config, PACKAGE, "pref_template_year", GEANY_TEMPLATES_FORMAT_YEAR);
template_prefs.date_format = utils_get_setting_string(config, PACKAGE, "pref_template_date", GEANY_TEMPLATES_FORMAT_DATE);
template_prefs.datetime_format = utils_get_setting_string(config, PACKAGE, "pref_template_datetime", GEANY_TEMPLATES_FORMAT_DATETIME);

View File

@ -272,7 +272,7 @@ gint socket_init(gint argc, gchar **argv)
return -1;
#else
gchar *display_name = gdk_get_display();
gchar *hostname = utils_get_hostname();
const gchar *hostname = g_get_host_name();
gchar *p;
if (display_name == NULL)
@ -293,7 +293,6 @@ gint socket_init(gint argc, gchar **argv)
app->configdir, G_DIR_SEPARATOR, hostname, display_name);
g_free(display_name);
g_free(hostname);
/* check whether the real user id is the same as this of the socket file */
check_socket_permissions();

View File

@ -637,19 +637,6 @@ gchar utils_brace_opposite(gchar ch)
}
gchar *utils_get_hostname(void)
{
#ifdef G_OS_WIN32
return win32_get_hostname();
#elif defined(HAVE_GETHOSTNAME)
gchar hostname[100];
if (gethostname(hostname, sizeof(hostname)) == 0)
return g_strdup(hostname);
#endif
return g_strdup("localhost");
}
/* Checks whether the given file can be written. locale_filename is expected in locale encoding.
* Returns 0 if it can be written, otherwise it returns errno */
gint utils_is_file_writable(const gchar *locale_filename)

View File

@ -182,8 +182,6 @@ gchar *utils_remove_ext_from_filename(const gchar *filename);
gchar utils_brace_opposite(gchar ch);
gchar *utils_get_hostname(void);
gint utils_string_find(GString *haystack, gint start, gint end, const gchar *needle);
gint utils_string_replace(GString *str, gint pos, gint len, const gchar *replace);

View File

@ -844,18 +844,6 @@ void win32_init_debug_code(void)
}
gchar *win32_get_hostname(void)
{
gchar hostname[100];
DWORD size = sizeof(hostname);
if (GetComputerName(hostname, &size))
return g_strdup(hostname);
else
return g_strdup("localhost");
}
static gchar *create_temp_file(void)
{
gchar *name;

View File

@ -52,8 +52,6 @@ void win32_init_debug_code(void);
void win32_set_working_directory(const gchar *dir);
gchar *win32_get_hostname(void);
gboolean win32_get_exit_status(GPid child_pid);
gboolean win32_spawn(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags flags,

View File

@ -63,9 +63,6 @@
/* Define to 1 if you have the `getcwd' function. */
#define HAVE_GETCWD 1
/* Define to 1 if you have the `gethostname' function. */
//#define HAVE_GETHOSTNAME 1
/* Define to 1 if you have the `getpagesize' function. */
#define HAVE_GETPAGESIZE 1

View File

@ -197,7 +197,6 @@ def configure(conf):
conf.check_cc(function_name='fgetpos', header_name='stdio.h', mandatory=False)
conf.check_cc(function_name='ftruncate', header_name='unistd.h', mandatory=False)
conf.check_cc(function_name='gethostname', header_name='unistd.h', mandatory=False)
conf.check_cc(function_name='mkstemp', header_name='stdlib.h', mandatory=False)
conf.check_cc(function_name='strstr', header_name='string.h')