[geany/geany] 82f82e: Use GLib's portable version gethostname(): g_get_host_name()

Colomban Wendling git-noreply at xxxxx
Sat Aug 17 22:52:48 UTC 2013


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sat, 17 Aug 2013 22:52:48 UTC
Commit:      82f82ed372a21d1f1648e79ddc27029d5d9d2ea7
             https://github.com/geany/geany/commit/82f82ed372a21d1f1648e79ddc27029d5d9d2ea7

Log Message:
-----------
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.


Modified Paths:
--------------
    configure.ac
    src/keyfile.c
    src/socket.c
    src/utils.c
    src/utils.h
    src/win32.c
    src/win32.h
    win32-config.h
    wscript

Modified: configure.ac
2 files changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -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
 


Modified: src/keyfile.c
4 files changed, 1 insertions(+), 3 deletions(-)
===================================================================
@@ -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);


Modified: src/socket.c
3 files changed, 1 insertions(+), 2 deletions(-)
===================================================================
@@ -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();


Modified: src/utils.c
13 files changed, 0 insertions(+), 13 deletions(-)
===================================================================
@@ -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)


Modified: src/utils.h
2 files changed, 0 insertions(+), 2 deletions(-)
===================================================================
@@ -182,8 +182,6 @@
 
 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);


Modified: src/win32.c
12 files changed, 0 insertions(+), 12 deletions(-)
===================================================================
@@ -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;


Modified: src/win32.h
2 files changed, 0 insertions(+), 2 deletions(-)
===================================================================
@@ -52,8 +52,6 @@ gchar *win32_show_project_open_dialog(GtkWidget *parent, const gchar *title,
 
 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,


Modified: win32-config.h
3 files changed, 0 insertions(+), 3 deletions(-)
===================================================================
@@ -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
 


Modified: wscript
1 files changed, 0 insertions(+), 1 deletions(-)
===================================================================
@@ -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')
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list