Mercurial > pidgin
comparison 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 |
comparison
equal
deleted
inserted
replaced
23537:ad0d0efa30dd | 23538:399975ad001c |
---|---|
4721 } | 4721 } |
4722 | 4722 |
4723 return g_string_free(string, FALSE); | 4723 return g_string_free(string, FALSE); |
4724 } | 4724 } |
4725 | 4725 |
4726 const gchar * | |
4727 purple_get_host_name(void) | |
4728 { | |
4729 #if GLIB_CHECK_VERSION(2,8,0) | |
4730 return g_get_host_name(); | |
4731 #else | |
4732 static char hostname[256]; | |
4733 int ret = gethostname(hostname, sizeof(hostname)); | |
4734 hostname[sizeof(hostname) - 1] = '\0'; | |
4735 | |
4736 if (ret == -1 || hostname[0] == '\0') { | |
4737 purple_debug_info("purple_get_host_name: ", "could not find host name"); | |
4738 return "localhost"; | |
4739 } else { | |
4740 return hostname; | |
4741 } | |
4742 #endif | |
4743 } |