Add support for getting hostname on Windows.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2246 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2008-02-10 17:53:18 +00:00
parent 6cd65c7f59
commit d60378dd98
4 changed files with 23 additions and 13 deletions

View File

@ -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 <enrico(dot)troeger(at)uvena(dot)de>

View File

@ -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");
}

View File

@ -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

View File

@ -59,4 +59,6 @@ void win32_init_debug_code();
gchar *win32_get_appdata_folder();
gchar *win32_get_hostname();
#endif