Mercurial > pidgin
diff libpurple/util.c @ 23538:399975ad001c
Add purple_get_host_name to get the hostname of the machine.
This is a replacement for g_get_host_name in glib2.8+. Thanks to Phil
Hannent and Marcus Lundblad for the initial patch. References #5627.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 13 Jul 2008 18:01:57 +0000 |
parents | 276925996951 |
children | 27eacd38c721 2ecd716746e6 |
line wrap: on
line diff
--- a/libpurple/util.c Sun Jul 13 17:20:41 2008 +0000 +++ b/libpurple/util.c Sun Jul 13 18:01:57 2008 +0000 @@ -4723,3 +4723,21 @@ return g_string_free(string, FALSE); } +const gchar * +purple_get_host_name(void) +{ +#if GLIB_CHECK_VERSION(2,8,0) + return g_get_host_name(); +#else + static char hostname[256]; + int ret = gethostname(hostname, sizeof(hostname)); + hostname[sizeof(hostname) - 1] = '\0'; + + if (ret == -1 || hostname[0] == '\0') { + purple_debug_info("purple_get_host_name: ", "could not find host name"); + return "localhost"; + } else { + return hostname; + } +#endif +}