authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2020-03-05 19:53:58-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-05 20:46:28-05:00
logd31b65e762fbf59d29780d4cbf7be1ab824a67de
treef264cc180948c1880b0173d782ec9d0546f818ba
parent428677ea361447949f274587faa41656ce8199ab

std: fix sendfile on macOS and FreeBSD

- fix std.os.sendfile/FreeBSD use correct in/out fd_t - fix std.os.sendfile/macOS use correct in/out fd_t - undo 1141bfb21b82f8d3fc353e968a591f2ad9aaa571 (no longer needed) - fix c.freebsd.sendfile use off_t value - fix c.freebsd.sendfile decl correct in/out fd_t - fix c.darwin.sendfile decl correct in/out fd_t fix signature param names

3 files changed, 8 insertions(+), 9 deletions(-)

lib/std/c/darwin.zig+1-1
......@@ -63,8 +63,8 @@ pub const sf_hdtr = extern struct {
6363};
6464
6565pub extern "c" fn sendfile(
66 out_fd: fd_t,
6766 in_fd: fd_t,
67 out_fd: fd_t,
6868 offset: off_t,
6969 len: *off_t,
7070 sf_hdtr: ?*sf_hdtr,
lib/std/c/freebsd.zig+2-2
......@@ -15,9 +15,9 @@ pub const sf_hdtr = extern struct {
1515 trl_cnt: c_int,
1616};
1717pub extern "c" fn sendfile(
18 out_fd: fd_t,
1918 in_fd: fd_t,
20 offset: ?*off_t,
19 out_fd: fd_t,
20 offset: off_t,
2121 nbytes: usize,
2222 sf_hdtr: ?*sf_hdtr,
2323 sbytes: ?*off_t,
lib/std/os.zig+5-6
......@@ -3734,7 +3734,8 @@ pub fn sendfile(
37343734
37353735 while (true) {
37363736 var sbytes: off_t = undefined;
3737 const err = errno(system.sendfile(out_fd, in_fd, in_offset, adjusted_count, hdtr, &sbytes, flags));
3737 const offset = @bitCast(off_t, in_offset);
3738 const err = errno(system.sendfile(in_fd, out_fd, offset, adjusted_count, hdtr, &sbytes, flags));
37383739 const amt = @bitCast(usize, sbytes);
37393740 switch (err) {
37403741 0 => return amt,
......@@ -3813,19 +3814,17 @@ pub fn sendfile(
38133814 while (true) {
38143815 var sbytes: off_t = adjusted_count;
38153816 const signed_offset = @bitCast(i64, in_offset);
3816 const err = errno(system.sendfile(out_fd, in_fd, signed_offset, &sbytes, hdtr, flags));
3817 const err = errno(system.sendfile(in_fd, out_fd, signed_offset, &sbytes, hdtr, flags));
38173818 const amt = @bitCast(usize, sbytes);
38183819 switch (err) {
38193820 0 => return amt,
38203821
3822 EBADF => unreachable, // Always a race condition.
38213823 EFAULT => unreachable, // Segmentation fault.
38223824 EINVAL => unreachable,
38233825 ENOTCONN => unreachable, // `out_fd` is an unconnected socket.
38243826
3825 // On macOS version 10.14.6, I observed Darwin return EBADF when
3826 // using sendfile on a valid open file descriptor of a file
3827 // system file.
3828 ENOTSUP, ENOTSOCK, ENOSYS, EBADF => break :sf,
3827 ENOTSUP, ENOTSOCK, ENOSYS => break :sf,
38293828
38303829 EINTR => if (amt != 0) return amt else continue,
38313830