use close$NOCANCEL on darwin

This commit is contained in:
Andrew Kelley 2019-05-27 14:41:13 -04:00
parent 13265cf7c7
commit b3dc1c380d
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 8 additions and 3 deletions

View File

@ -32,6 +32,7 @@ pub extern "c" fn abort() noreturn;
pub extern "c" fn exit(code: c_int) noreturn;
pub extern "c" fn isatty(fd: fd_t) c_int;
pub extern "c" fn close(fd: fd_t) c_int;
pub extern "c" fn @"close$NOCANCEL"(fd: fd_t) c_int;
pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
pub extern "c" fn lseek(fd: fd_t, offset: isize, whence: c_int) isize;

View File

@ -74,9 +74,13 @@ pub fn close(fd: fd_t) void {
return windows.CloseHandle(fd);
}
if (wasi.is_the_target) {
switch (wasi.fd_close(fd)) {
0 => return,
else => |err| return unexpectedErrno(err),
_ = wasi.fd_close(fd);
}
if (darwin.is_the_target) {
// This avoids the EINTR problem.
switch (darwin.getErrno(darwin.@"close$NOCANCEL"(fd))) {
EBADF => unreachable, // Always a race condition.
else => return,
}
}
switch (errno(system.close(fd))) {