tar: support -T - and -X -
[oweals/busybox.git] / libbb / safe_gethostname.c
index 7407fb78299c59aa8db1756b76f9ac710c6c0ade..bdb98963113ffe8d613f48b0961e39aa93bf2025 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Copyright (C) 2008 Tito Ragusa <farmatito@tiscali.it>
  *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
 /*
@@ -59,8 +59,16 @@ char* FAST_FUNC safe_gethostname(void)
  */
 char* FAST_FUNC safe_getdomainname(void)
 {
+#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
+       /* 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
 }