| author | |
| committer | |
| log | 0353c9601a7a72cf453738818d0fba4e980512ba |
| tree | 833e668796e537ddb51bbd59df2612068ffbe9e3 |
| parent | c3dadfa95b01d140460eb3d3d47d13859302f298 |
| parent | 6418f9ae91e2444da0743ea0fb0c81fc07ea86a9 |
| signature | Signed by PGP key 4AEE18F83AFDEB23 |
std: Fixed pipe2 fallback7 files changed, 47 insertions(+), 20 deletions(-)
lib/std/c.zig-1| ... | ... | @@ -108,7 +108,6 @@ pub extern "c" fn fork() c_int; |
| 108 | 108 | pub extern "c" fn access(path: [*:0]const u8, mode: c_uint) c_int; |
| 109 | 109 | pub extern "c" fn faccessat(dirfd: fd_t, path: [*:0]const u8, mode: c_uint, flags: c_uint) c_int; |
| 110 | 110 | pub extern "c" fn pipe(fds: *[2]fd_t) c_int; |
| 111 | pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; | |
| 112 | 111 | pub extern "c" fn mkdir(path: [*:0]const u8, mode: c_uint) c_int; |
| 113 | 112 | pub extern "c" fn mkdirat(dirfd: fd_t, path: [*:0]const u8, mode: u32) c_int; |
| 114 | 113 | pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int; |
lib/std/c/dragonfly.zig+1| ... | ... | @@ -13,6 +13,7 @@ pub fn _errno() *c_int { |
| 13 | 13 | pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize; |
| 14 | 14 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
| 15 | 15 | pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize; |
| 16 | pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; | |
| 16 | 17 | |
| 17 | 18 | pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int; |
| 18 | 19 | pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int; |
lib/std/c/freebsd.zig+1| ... | ... | @@ -14,6 +14,7 @@ pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
| 14 | 14 | pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize; |
| 15 | 15 | |
| 16 | 16 | pub extern "c" fn pthread_getthreadid_np() c_int; |
| 17 | pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; | |
| 17 | 18 | |
| 18 | 19 | pub extern "c" fn posix_memalign(memptr: *?*c_void, alignment: usize, size: usize) c_int; |
| 19 | 20 | pub extern "c" fn malloc_usable_size(?*const c_void) usize; |
lib/std/c/linux.zig+1| ... | ... | @@ -86,6 +86,7 @@ pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_ |
| 86 | 86 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
| 87 | 87 | |
| 88 | 88 | pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int; |
| 89 | pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; | |
| 89 | 90 | |
| 90 | 91 | pub extern "c" fn fallocate(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int; |
| 91 | 92 |
lib/std/c/netbsd.zig+1| ... | ... | @@ -16,6 +16,7 @@ pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_ |
| 16 | 16 | |
| 17 | 17 | pub extern "c" fn _lwp_self() lwpid_t; |
| 18 | 18 | |
| 19 | pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; | |
| 19 | 20 | pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void; |
| 20 | 21 | pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int; |
| 21 | 22 | pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int; |
lib/std/c/openbsd.zig+1| ... | ... | @@ -17,6 +17,7 @@ pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_ |
| 17 | 17 | pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void; |
| 18 | 18 | |
| 19 | 19 | pub extern "c" fn getthrid() pid_t; |
| 20 | pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; | |
| 20 | 21 | |
| 21 | 22 | pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize; |
| 22 | 23 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
lib/std/os.zig+42-19| ... | ... | @@ -3755,31 +3755,54 @@ pub fn pipe() PipeError![2]fd_t { |
| 3755 | 3755 | } |
| 3756 | 3756 | |
| 3757 | 3757 | pub fn pipe2(flags: u32) PipeError![2]fd_t { |
| 3758 | if (comptime std.Target.current.isDarwin()) { | |
| 3759 | var fds: [2]fd_t = try pipe(); | |
| 3760 | if (flags == 0) return fds; | |
| 3761 | errdefer { | |
| 3762 | close(fds[0]); | |
| 3763 | close(fds[1]); | |
| 3764 | } | |
| 3765 | for (fds) |fd| switch (errno(system.fcntl(fd, F_SETFL, flags))) { | |
| 3766 | 0 => {}, | |
| 3758 | if (@hasDecl(system, "pipe2")) { | |
| 3759 | var fds: [2]fd_t = undefined; | |
| 3760 | switch (errno(system.pipe2(&fds, flags))) { | |
| 3761 | 0 => return fds, | |
| 3767 | 3762 | EINVAL => unreachable, // Invalid flags |
| 3768 | EBADF => unreachable, // Always a race condition | |
| 3763 | EFAULT => unreachable, // Invalid fds pointer | |
| 3764 | ENFILE => return error.SystemFdQuotaExceeded, | |
| 3765 | EMFILE => return error.ProcessFdQuotaExceeded, | |
| 3769 | 3766 | else => |err| return unexpectedErrno(err), |
| 3770 | }; | |
| 3767 | } | |
| 3768 | } | |
| 3769 | ||
| 3770 | var fds: [2]fd_t = try pipe(); | |
| 3771 | errdefer { | |
| 3772 | close(fds[0]); | |
| 3773 | close(fds[1]); | |
| 3774 | } | |
| 3775 | ||
| 3776 | if (flags == 0) | |
| 3771 | 3777 | return fds; |
| 3778 | ||
| 3779 | // O_CLOEXEC is special, it's a file descriptor flag and must be set using | |
| 3780 | // F_SETFD. | |
| 3781 | if (flags & O_CLOEXEC != 0) { | |
| 3782 | for (fds) |fd| { | |
| 3783 | switch (errno(system.fcntl(fd, F_SETFD, @as(u32, FD_CLOEXEC)))) { | |
| 3784 | 0 => {}, | |
| 3785 | EINVAL => unreachable, // Invalid flags | |
| 3786 | EBADF => unreachable, // Always a race condition | |
| 3787 | else => |err| return unexpectedErrno(err), | |
| 3788 | } | |
| 3789 | } | |
| 3772 | 3790 | } |
| 3773 | 3791 | |
| 3774 | var fds: [2]fd_t = undefined; | |
| 3775 | switch (errno(system.pipe2(&fds, flags))) { | |
| 3776 | 0 => return fds, | |
| 3777 | EINVAL => unreachable, // Invalid flags | |
| 3778 | EFAULT => unreachable, // Invalid fds pointer | |
| 3779 | ENFILE => return error.SystemFdQuotaExceeded, | |
| 3780 | EMFILE => return error.ProcessFdQuotaExceeded, | |
| 3781 | else => |err| return unexpectedErrno(err), | |
| 3792 | const new_flags = flags & ~@as(u32, O_CLOEXEC); | |
| 3793 | // Set every other flag affecting the file status using F_SETFL. | |
| 3794 | if (new_flags != 0) { | |
| 3795 | for (fds) |fd| { | |
| 3796 | switch (errno(system.fcntl(fd, F_SETFL, new_flags))) { | |
| 3797 | 0 => {}, | |
| 3798 | EINVAL => unreachable, // Invalid flags | |
| 3799 | EBADF => unreachable, // Always a race condition | |
| 3800 | else => |err| return unexpectedErrno(err), | |
| 3801 | } | |
| 3802 | } | |
| 3782 | 3803 | } |
| 3804 | ||
| 3805 | return fds; | |
| 3783 | 3806 | } |
| 3784 | 3807 | |
| 3785 | 3808 | pub const SysCtlError = error{ |