From 9b9f36aefc23f3cbff67e0fedda1a379ad460f81 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Thu, 18 May 2017 10:06:36 -0700 Subject: [PATCH] Use NOCANCEL variants for close on Mac The default on OS X does not provide clear errors, instead the NOCANCEL variants should be used. These are available as of OS X 10.6 onwards. --- libc-test/build.rs | 5 ++++- src/unix/mod.rs | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 61a0407768b14..b08bcce0d6dc9 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -500,7 +500,7 @@ fn main() { "backtrace" | "sysinfo" | "newlocale" | "duplocale" | "freelocale" | "uselocale" | "nl_langinfo_l" | "wcslen" | "wcstombs" if uclibc => 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, @@ -511,6 +511,9 @@ fn main() { // https://github.com/rust-lang/libc/pull/585#discussion_r114561460 "res_init" if apple => true, + // On Mac we don't use the default `close()`, instead using their $NOCANCEL variants. + "close" if apple => true, + _ => false, } }); diff --git a/src/unix/mod.rs b/src/unix/mod.rs index c2d1f10e40638..8d794e7459072 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -405,7 +405,9 @@ extern { pub fn lchown(path: *const c_char, uid: uid_t, gid: gid_t) -> ::c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "close$UNIX2003")] + link_name = "close$NOCANCEL$UNIX2003")] + #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), + link_name = "close$NOCANCEL")] pub fn close(fd: ::c_int) -> ::c_int; pub fn dup(fd: ::c_int) -> ::c_int; pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int;