From 66106e7c9cb9f2c5ebf1b98c49c9f71acf702d71 Mon Sep 17 00:00:00 2001 From: Daniel Klessing Date: Wed, 9 Nov 2011 15:55:18 +0100 Subject: Include safe_gethostname() Fixed compilation under mingw32 by making safe_gethostname.c globally available, as the compiler couldn't find safe_gethostname() --- libbb/Kbuild.src | 2 +- libbb/safe_gethostname.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index b88fa8fe7..f815c6dbc 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src @@ -78,6 +78,7 @@ lib-y += read_printf.o lib-y += recursive_action.o lib-y += remove_file.o lib-y += run_shell.o +lib-y += safe_gethostname.o lib-y += safe_poll.o lib-y += safe_strncpy.o lib-y += safe_write.o @@ -116,7 +117,6 @@ lib-$(CONFIG_PLATFORM_POSIX) += login.o lib-$(CONFIG_PLATFORM_POSIX) += makedev.o lib-$(CONFIG_PLATFORM_POSIX) += match_fstype.o lib-$(CONFIG_PLATFORM_POSIX) += read_key.o -lib-$(CONFIG_PLATFORM_POSIX) += safe_gethostname.o lib-$(CONFIG_PLATFORM_POSIX) += signals.o lib-$(CONFIG_PLATFORM_POSIX) += udp_io.o lib-$(CONFIG_PLATFORM_POSIX) += xgethostbyname.o diff --git a/libbb/safe_gethostname.c b/libbb/safe_gethostname.c index bdb989631..233a6a418 100644 --- a/libbb/safe_gethostname.c +++ b/libbb/safe_gethostname.c @@ -25,7 +25,9 @@ */ #include "libbb.h" +#if defined(__linux__) #include +#endif /* * On success return the current malloced and NUL terminated hostname. @@ -35,6 +37,7 @@ */ char* FAST_FUNC safe_gethostname(void) { +#if defined(__linux__) struct utsname uts; /* The length of the arrays in a struct utsname is unspecified; @@ -49,6 +52,13 @@ char* FAST_FUNC safe_gethostname(void) /* Uname can fail only if you pass a bad pointer to it. */ uname(&uts); return xstrndup(!uts.nodename[0] ? "?" : uts.nodename, sizeof(uts.nodename)); +#else + /* We really don't care about people with host names wider than most screens */ + char buf[256]; + int r = gethostname(buf, sizeof(buf)); + buf[sizeof(buf)-1] = '\0'; + return xstrdup(r < 0 ? "?" : buf); +#endif } /* @@ -66,9 +76,12 @@ char* FAST_FUNC safe_getdomainname(void) 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); + */ + return xstrdup("?"); #endif } -- cgit v1.2.3-55-g6feb