diff options
author | Daniel Klessing <daniel.klessing@de.fujitsu.com> | 2011-11-09 15:55:18 +0100 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2011-11-21 11:24:44 +0700 |
commit | 66106e7c9cb9f2c5ebf1b98c49c9f71acf702d71 (patch) | |
tree | 42e5371fda6e0b8bab63fb4e4164b7a5ec2f9e55 | |
parent | 681755bcf5506109375e6fb9fc777461a704cf36 (diff) | |
download | busybox-w32-66106e7c9cb9f2c5ebf1b98c49c9f71acf702d71.tar.gz busybox-w32-66106e7c9cb9f2c5ebf1b98c49c9f71acf702d71.tar.bz2 busybox-w32-66106e7c9cb9f2c5ebf1b98c49c9f71acf702d71.zip |
Include safe_gethostname()
Fixed compilation under mingw32 by making safe_gethostname.c globally
available, as the compiler couldn't find safe_gethostname()
-rw-r--r-- | libbb/Kbuild.src | 2 | ||||
-rw-r--r-- | libbb/safe_gethostname.c | 13 |
2 files changed, 14 insertions, 1 deletions
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 | |||
78 | lib-y += recursive_action.o | 78 | lib-y += recursive_action.o |
79 | lib-y += remove_file.o | 79 | lib-y += remove_file.o |
80 | lib-y += run_shell.o | 80 | lib-y += run_shell.o |
81 | lib-y += safe_gethostname.o | ||
81 | lib-y += safe_poll.o | 82 | lib-y += safe_poll.o |
82 | lib-y += safe_strncpy.o | 83 | lib-y += safe_strncpy.o |
83 | lib-y += safe_write.o | 84 | lib-y += safe_write.o |
@@ -116,7 +117,6 @@ lib-$(CONFIG_PLATFORM_POSIX) += login.o | |||
116 | lib-$(CONFIG_PLATFORM_POSIX) += makedev.o | 117 | lib-$(CONFIG_PLATFORM_POSIX) += makedev.o |
117 | lib-$(CONFIG_PLATFORM_POSIX) += match_fstype.o | 118 | lib-$(CONFIG_PLATFORM_POSIX) += match_fstype.o |
118 | lib-$(CONFIG_PLATFORM_POSIX) += read_key.o | 119 | lib-$(CONFIG_PLATFORM_POSIX) += read_key.o |
119 | lib-$(CONFIG_PLATFORM_POSIX) += safe_gethostname.o | ||
120 | lib-$(CONFIG_PLATFORM_POSIX) += signals.o | 120 | lib-$(CONFIG_PLATFORM_POSIX) += signals.o |
121 | lib-$(CONFIG_PLATFORM_POSIX) += udp_io.o | 121 | lib-$(CONFIG_PLATFORM_POSIX) += udp_io.o |
122 | lib-$(CONFIG_PLATFORM_POSIX) += xgethostbyname.o | 122 | 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 @@ | |||
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include "libbb.h" | 27 | #include "libbb.h" |
28 | #if defined(__linux__) | ||
28 | #include <sys/utsname.h> | 29 | #include <sys/utsname.h> |
30 | #endif | ||
29 | 31 | ||
30 | /* | 32 | /* |
31 | * On success return the current malloced and NUL terminated hostname. | 33 | * On success return the current malloced and NUL terminated hostname. |
@@ -35,6 +37,7 @@ | |||
35 | */ | 37 | */ |
36 | char* FAST_FUNC safe_gethostname(void) | 38 | char* FAST_FUNC safe_gethostname(void) |
37 | { | 39 | { |
40 | #if defined(__linux__) | ||
38 | struct utsname uts; | 41 | struct utsname uts; |
39 | 42 | ||
40 | /* The length of the arrays in a struct utsname is unspecified; | 43 | /* The length of the arrays in a struct utsname is unspecified; |
@@ -49,6 +52,13 @@ char* FAST_FUNC safe_gethostname(void) | |||
49 | /* Uname can fail only if you pass a bad pointer to it. */ | 52 | /* Uname can fail only if you pass a bad pointer to it. */ |
50 | uname(&uts); | 53 | uname(&uts); |
51 | return xstrndup(!uts.nodename[0] ? "?" : uts.nodename, sizeof(uts.nodename)); | 54 | return xstrndup(!uts.nodename[0] ? "?" : uts.nodename, sizeof(uts.nodename)); |
55 | #else | ||
56 | /* We really don't care about people with host names wider than most screens */ | ||
57 | char buf[256]; | ||
58 | int r = gethostname(buf, sizeof(buf)); | ||
59 | buf[sizeof(buf)-1] = '\0'; | ||
60 | return xstrdup(r < 0 ? "?" : buf); | ||
61 | #endif | ||
52 | } | 62 | } |
53 | 63 | ||
54 | /* | 64 | /* |
@@ -66,9 +76,12 @@ char* FAST_FUNC safe_getdomainname(void) | |||
66 | return xstrndup(!uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname)); | 76 | return xstrndup(!uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname)); |
67 | #else | 77 | #else |
68 | /* We really don't care about people with domain names wider than most screens */ | 78 | /* We really don't care about people with domain names wider than most screens */ |
79 | /* | ||
69 | char buf[256]; | 80 | char buf[256]; |
70 | int r = getdomainname(buf, sizeof(buf)); | 81 | int r = getdomainname(buf, sizeof(buf)); |
71 | buf[sizeof(buf)-1] = '\0'; | 82 | buf[sizeof(buf)-1] = '\0'; |
72 | return xstrdup(r < 0 ? "?" : buf); | 83 | return xstrdup(r < 0 ? "?" : buf); |
84 | */ | ||
85 | return xstrdup("?"); | ||
73 | #endif | 86 | #endif |
74 | } | 87 | } |