aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os/linux.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-03-03 02:03:22 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-03-03 02:25:26 -0500
commitc81345c8aec56a108f6f98001666a1552d65ce85 (patch)
tree6a18842256a157896d175d4e254811b9bf478090 /lib/std/os/linux.zig
parentbd287dd1942f0a72e6bd9dc8475bd4e7d34fa5f8 (diff)
downloadzig-c81345c8aec56a108f6f98001666a1552d65ce85.tar.gz
zig-c81345c8aec56a108f6f98001666a1552d65ce85.zip
breaking: std.os read/write functions + sendfile
* rework os.sendfile and add macosx support, and a fallback implementation for any OS. * fix sendto compile error * std.os write functions support partial writes. closes #3443. * std.os pread / pwrite functions can now return `error.Unseekable`. * std.fs.File read/write functions now have readAll/writeAll variants which loop to complete operations even when partial reads/writes happen. * Audit std.os read/write functions with respect to Linux returning EINVAL for lengths greater than 0x7fff0000. * std.os read/write shim functions do not unnecessarily loop. Since partial reads/writes are part of the API, the caller will be forced to loop anyway, and so that would just be code bloat. * Improve doc comments * Add a non-trivial test for std.os.sendfile * Fix std.os.pread on 32 bit Linux * Add missing SYS_sendfile bit on aarch64
Diffstat (limited to 'lib/std/os/linux.zig')
-rw-r--r--lib/std/os/linux.zig33
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig
index 95b1018a6b..c2fc06bc9b 100644
--- a/lib/std/os/linux.zig
+++ b/lib/std/os/linux.zig
@@ -316,8 +316,19 @@ pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) us
return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath));
}
-pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
- return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
+pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
+ if (@hasDecl(@This(), "SYS_pread64")) {
+ return syscall5(
+ SYS_pread64,
+ @bitCast(usize, @as(isize, fd)),
+ @ptrToInt(buf),
+ count,
+ @truncate(usize, offset),
+ @truncate(usize, offset >> 32),
+ );
+ } else {
+ return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
+ }
}
pub fn access(path: [*:0]const u8, mode: u32) usize {
@@ -846,11 +857,23 @@ pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const s
return syscall6(SYS_sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
}
-pub fn sendfile(outfd: i32, infd: i32, offset: ?*u64, count: usize) usize {
+pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {
if (@hasDecl(@This(), "SYS_sendfile64")) {
- return syscall4(SYS_sendfile64, @bitCast(usize, @as(isize, outfd)), @bitCast(usize, @as(isize, infd)), @ptrToInt(offset), count);
+ return syscall4(
+ SYS_sendfile64,
+ @bitCast(usize, @as(isize, outfd)),
+ @bitCast(usize, @as(isize, infd)),
+ @ptrToInt(offset),
+ count,
+ );
} else {
- return syscall4(SYS_sendfile, @bitCast(usize, @as(isize, outfd)), @bitCast(usize, @as(isize, infd)), @ptrToInt(offset), count);
+ return syscall4(
+ SYS_sendfile,
+ @bitCast(usize, @as(isize, outfd)),
+ @bitCast(usize, @as(isize, infd)),
+ @ptrToInt(offset),
+ count,
+ );
}
}