diff --git a/libc-test/build.rs b/libc-test/build.rs index 28ac5a51b97b4..2f59a442af184 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -77,6 +77,7 @@ fn main() { cfg.header("netinet/in.h"); cfg.header("netinet/ip.h"); cfg.header("netinet/tcp.h"); + cfg.header("resolv.h"); cfg.header("pthread.h"); cfg.header("dlfcn.h"); cfg.header("signal.h"); @@ -468,6 +469,16 @@ fn main() { // it's in a header file? "endpwent" if android => true, + // Apparently res_init exists on Android, but isn't defined in a header: + // https://mail.gnome.org/archives/commits-list/2013-May/msg01329.html + "res_init" if android => true, + + // On macOS and iOS, res_init is available, but requires linking with libresolv: + // http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html + // See discussion for skipping here: + // https://github.com/rust-lang/libc/pull/585#discussion_r114561460 + "res_init" if apple => true, + _ => false, } }); diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 7ebf0d9e0bac5..a235d6a422017 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -694,6 +694,14 @@ extern { res: *mut *mut addrinfo) -> ::c_int; pub fn freeaddrinfo(res: *mut addrinfo); pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char; + #[cfg_attr(any( + all(target_os = "linux", not(target_env = "musl")), + target_os = "freebsd", + target_os = "dragonfly"), + link_name = "__res_init")] + #[cfg_attr(any(target_os = "macos", target_os = "ios"), + link_name = "res_9_init")] + pub fn res_init() -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__gmtime_r50")] pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;