authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-07 11:28:42-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-07 11:28:42-05:00
log71873e71338fcdecf248d0fb994918ee943cd2e6
treedcc7be23496a297dcf36ca3bd1725b2fcc4ddfcb
parent0b5bcd2f56a84e66d5c700744ec1838381893667
signaturelock-open Commit is signed but in an unrecognized format.

implement os.pipe2 for darwin


2 files changed, 27 insertions(+), 1 deletions(-)

lib/std/fs.zig+4-1
...@@ -817,7 +817,10 @@ pub const Dir = struct {...@@ -817,7 +817,10 @@ pub const Dir = struct {
817 ) File.OpenError!File {817 ) File.OpenError!File {
818 const w = os.windows;818 const w = os.windows;
819819
820 var result = File{ .handle = undefined };820 var result = File{
821 .handle = undefined,
822 .io_mode = .blocking,
823 };
821824
822 const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) {825 const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) {
823 error.Overflow => return error.NameTooLong,826 error.Overflow => return error.NameTooLong,
lib/std/os.zig+23
...@@ -2528,6 +2528,29 @@ pub fn pipe() PipeError![2]fd_t {...@@ -2528,6 +2528,29 @@ pub fn pipe() PipeError![2]fd_t {
2528}2528}
25292529
2530pub fn pipe2(flags: u32) PipeError![2]fd_t {2530pub fn pipe2(flags: u32) PipeError![2]fd_t {
2531 if (comptime std.Target.current.isDarwin()) {
2532 var fds: [2]fd_t = undefined;
2533 switch (errno(system.pipe(&fds, flags))) {
2534 0 => {},
2535 EINVAL => unreachable, // Invalid flags
2536 EFAULT => unreachable, // Invalid fds pointer
2537 ENFILE => return error.SystemFdQuotaExceeded,
2538 EMFILE => return error.ProcessFdQuotaExceeded,
2539 else => |err| return unexpectedErrno(err),
2540 }
2541 errdefer {
2542 close(fds[0]);
2543 close(fds[1]);
2544 }
2545 for (fds) |fd| switch (errno(system.fcntl(fd, F_SETFL, flags))) {
2546 0 => {},
2547 EINVAL => unreachable, // Invalid flags
2548 EBADF => unreachable, // Always a race condition
2549 else => |err| return unexpectedErrno(err),
2550 };
2551 return fds;
2552 }
2553
2531 var fds: [2]fd_t = undefined;2554 var fds: [2]fd_t = undefined;
2532 switch (errno(system.pipe2(&fds, flags))) {2555 switch (errno(system.pipe2(&fds, flags))) {
2533 0 => return fds,2556 0 => return fds,