Skip to content

Commit 9b9f36a

Browse files
committed
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.
1 parent a285387 commit 9b9f36a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

libc-test/build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ fn main() {
500500
"backtrace" |
501501
"sysinfo" | "newlocale" | "duplocale" | "freelocale" | "uselocale" |
502502
"nl_langinfo_l" | "wcslen" | "wcstombs" if uclibc => true,
503-
503+
504504
// Apparently res_init exists on Android, but isn't defined in a header:
505505
// https://mail.gnome.org/archives/commits-list/2013-May/msg01329.html
506506
"res_init" if android => true,
@@ -511,6 +511,9 @@ fn main() {
511511
// https://github.com/rust-lang/libc/pull/585#discussion_r114561460
512512
"res_init" if apple => true,
513513

514+
// On Mac we don't use the default `close()`, instead using their $NOCANCEL variants.
515+
"close" if apple => true,
516+
514517
_ => false,
515518
}
516519
});

src/unix/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ extern {
405405
pub fn lchown(path: *const c_char, uid: uid_t,
406406
gid: gid_t) -> ::c_int;
407407
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
408-
link_name = "close$UNIX2003")]
408+
link_name = "close$NOCANCEL$UNIX2003")]
409+
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
410+
link_name = "close$NOCANCEL")]
409411
pub fn close(fd: ::c_int) -> ::c_int;
410412
pub fn dup(fd: ::c_int) -> ::c_int;
411413
pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int;

0 commit comments

Comments
 (0)