provide safe_gethostname() for non-linux systems
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 29 Mar 2010 09:20:00 +0000 (11:20 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 29 Mar 2010 09:20:00 +0000 (11:20 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/safe_gethostname.c

index e93254b..05e0954 100644 (file)
@@ -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
 }