From d60378dd98e3d237a0e67694ce4ce2893c2d0c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 10 Feb 2008 17:53:18 +0000 Subject: [PATCH] Add support for getting hostname on Windows. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2246 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 2 ++ src/utils.c | 20 +++++++------------- src/win32.c | 12 ++++++++++++ src/win32.h | 2 ++ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f39e535..ce8791d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,8 @@ time stamp. Before creating a new socket, delete a maybe existing socket and its symlink. + * src/utils.c, src/win32.c, src/win32.h: + Add support for getting hostname on Windows. 2008-02-08 Enrico Tröger diff --git a/src/utils.c b/src/utils.c index 46d39acc..d7f5ef7a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -699,20 +699,14 @@ gchar utils_brace_opposite(gchar ch) gchar *utils_get_hostname() { -#ifndef HAVE_GETHOSTNAME - return g_strdup("localhost"); -#else - gchar *host = g_malloc(25); - if (gethostname(host, 24) == 0) - { - return host; - } - else - { - g_free(host); - return g_strdup("localhost"); - } +#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"); } diff --git a/src/win32.c b/src/win32.c index 4ae6b088..93919c25 100644 --- a/src/win32.c +++ b/src/win32.c @@ -700,4 +700,16 @@ gchar *win32_get_appdata_folder() return folder; } + +gchar *win32_get_hostname() +{ + gchar hostname[100]; + DWORD size = sizeof(hostname); + + if (GetComputerName(hostname, &size)) + return g_strdup(hostname); + else + return g_strdup("localhost"); +} + #endif diff --git a/src/win32.h b/src/win32.h index 43ea6e5b..b070369a 100644 --- a/src/win32.h +++ b/src/win32.h @@ -59,4 +59,6 @@ void win32_init_debug_code(); gchar *win32_get_appdata_folder(); +gchar *win32_get_hostname(); + #endif