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 1141bfb21b (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
master
Michael Dusan 2020-03-05 19:53:58 -05:00 committed by Andrew Kelley
parent 428677ea36
commit d31b65e762
3 changed files with 8 additions and 9 deletions

View File

@ -63,8 +63,8 @@ pub const sf_hdtr = extern struct {
};
pub extern "c" fn sendfile(
out_fd: fd_t,
in_fd: fd_t,
out_fd: fd_t,
offset: off_t,
len: *off_t,
sf_hdtr: ?*sf_hdtr,

View File

@ -15,9 +15,9 @@ pub const sf_hdtr = extern struct {
trl_cnt: c_int,
};
pub extern "c" fn sendfile(
out_fd: fd_t,
in_fd: fd_t,
offset: ?*off_t,
out_fd: fd_t,
offset: off_t,
nbytes: usize,
sf_hdtr: ?*sf_hdtr,
sbytes: ?*off_t,

View File

@ -3734,7 +3734,8 @@ pub fn sendfile(
while (true) {
var sbytes: off_t = undefined;
const err = errno(system.sendfile(out_fd, in_fd, in_offset, adjusted_count, hdtr, &sbytes, flags));
const offset = @bitCast(off_t, in_offset);
const err = errno(system.sendfile(in_fd, out_fd, offset, adjusted_count, hdtr, &sbytes, flags));
const amt = @bitCast(usize, sbytes);
switch (err) {
0 => return amt,
@ -3813,19 +3814,17 @@ pub fn sendfile(
while (true) {
var sbytes: off_t = adjusted_count;
const signed_offset = @bitCast(i64, in_offset);
const err = errno(system.sendfile(out_fd, in_fd, signed_offset, &sbytes, hdtr, flags));
const err = errno(system.sendfile(in_fd, out_fd, signed_offset, &sbytes, hdtr, flags));
const amt = @bitCast(usize, sbytes);
switch (err) {
0 => return amt,
EBADF => unreachable, // Always a race condition.
EFAULT => unreachable, // Segmentation fault.
EINVAL => unreachable,
ENOTCONN => unreachable, // `out_fd` is an unconnected socket.
// On macOS version 10.14.6, I observed Darwin return EBADF when
// using sendfile on a valid open file descriptor of a file
// system file.
ENOTSUP, ENOTSOCK, ENOSYS, EBADF => break :sf,
ENOTSUP, ENOTSOCK, ENOSYS => break :sf,
EINTR => if (amt != 0) return amt else continue,