implement os.pipe2 for darwin

master
Andrew Kelley 2020-02-07 11:28:42 -05:00
parent 0b5bcd2f56
commit 71873e7133
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 27 additions and 1 deletions

View File

@ -817,7 +817,10 @@ pub const Dir = struct {
) File.OpenError!File {
const w = os.windows;
var result = File{ .handle = undefined };
var result = File{
.handle = undefined,
.io_mode = .blocking,
};
const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) {
error.Overflow => return error.NameTooLong,

View File

@ -2528,6 +2528,29 @@ pub fn pipe() PipeError![2]fd_t {
}
pub fn pipe2(flags: u32) PipeError![2]fd_t {
if (comptime std.Target.current.isDarwin()) {
var fds: [2]fd_t = undefined;
switch (errno(system.pipe(&fds, flags))) {
0 => {},
EINVAL => unreachable, // Invalid flags
EFAULT => unreachable, // Invalid fds pointer
ENFILE => return error.SystemFdQuotaExceeded,
EMFILE => return error.ProcessFdQuotaExceeded,
else => |err| return unexpectedErrno(err),
}
errdefer {
close(fds[0]);
close(fds[1]);
}
for (fds) |fd| switch (errno(system.fcntl(fd, F_SETFL, flags))) {
0 => {},
EINVAL => unreachable, // Invalid flags
EBADF => unreachable, // Always a race condition
else => |err| return unexpectedErrno(err),
};
return fds;
}
var fds: [2]fd_t = undefined;
switch (errno(system.pipe2(&fds, flags))) {
0 => return fds,