[git commit master] provide safe_gethostname() for non-linux systems

Denys Vlasenko vda.linux at googlemail.com
Mon Mar 29 09:20:00 UTC 2010


commit: http://git.busybox.net/busybox/commit/?id=1d448cff653a9a68f6320d01c9f0505385aa38bd
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 libbb/safe_gethostname.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libbb/safe_gethostname.c b/libbb/safe_gethostname.c
index e93254b..05e0954 100644
--- a/libbb/safe_gethostname.c
+++ b/libbb/safe_gethostname.c
@@ -59,12 +59,16 @@ char* FAST_FUNC safe_gethostname(void)
  */
 char* FAST_FUNC safe_getdomainname(void)
 {
-/* The field domainname of struct utsname is Linux specific. */
 #if defined(__linux__)
+/* The field domainname of struct utsname is Linux specific. */
 	struct utsname uts;
 	uname(&uts);
 	return xstrndup(!uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname));
 #else
-	return xstrdup("?");
+	/* We really don't care about people with domain names wider than most screens */
+	char buf[256];
+	int r = getdomainname(buf, sizeof(buf));
+	buf[sizeof(buf)-1] = '\0';
+	return xstrdup(r < 0 ? "?" : buf);
 #endif
 }
-- 
1.6.3.3



More information about the busybox-cvs mailing list