aboutsummaryrefslogtreecommitdiff
path: root/libbb/safe_gethostname.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/safe_gethostname.c')
-rw-r--r--libbb/safe_gethostname.c22
1 files changed, 0 insertions, 22 deletions
diff --git a/libbb/safe_gethostname.c b/libbb/safe_gethostname.c
index bdb989631..cac99ae03 100644
--- a/libbb/safe_gethostname.c
+++ b/libbb/safe_gethostname.c
@@ -50,25 +50,3 @@ char* FAST_FUNC safe_gethostname(void)
50 uname(&uts); 50 uname(&uts);
51 return xstrndup(!uts.nodename[0] ? "?" : uts.nodename, sizeof(uts.nodename)); 51 return xstrndup(!uts.nodename[0] ? "?" : uts.nodename, sizeof(uts.nodename));
52} 52}
53
54/*
55 * On success return the current malloced and NUL terminated domainname.
56 * On error return malloced and NUL terminated string "?".
57 * This is an illegal first character for a domainname.
58 * The returned malloced string must be freed by the caller.
59 */
60char* FAST_FUNC safe_getdomainname(void)
61{
62#if defined(__linux__)
63/* The field domainname of struct utsname is Linux specific. */
64 struct utsname uts;
65 uname(&uts);
66 return xstrndup(!uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname));
67#else
68 /* We really don't care about people with domain names wider than most screens */
69 char buf[256];
70 int r = getdomainname(buf, sizeof(buf));
71 buf[sizeof(buf)-1] = '\0';
72 return xstrdup(r < 0 ? "?" : buf);
73#endif
74}