diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-03-03 10:15:37 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-03 10:15:37 -0500 |
| commit | 226b801830857a9075fdd8180739105bb73eed0e (patch) | |
| tree | 48c684f434c6a44d2e0684adc69b31862dcb90ab /lib/std/os/linux.zig | |
| parent | 387418277a4964714ddaec3336a602ec87dde0f9 (diff) | |
| parent | 9d6cc75ce3be9ab291614fc0d4361877e9200126 (diff) | |
| download | zig-226b801830857a9075fdd8180739105bb73eed0e.tar.gz zig-226b801830857a9075fdd8180739105bb73eed0e.zip | |
Merge pull request #4612 from ziglang/os-read-write-sendfile
std.os read/write functions + sendfile
Diffstat (limited to 'lib/std/os/linux.zig')
| -rw-r--r-- | lib/std/os/linux.zig | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 30dba85e51..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,6 +857,26 @@ 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: ?*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, + ); + } else { + return syscall4( + SYS_sendfile, + @bitCast(usize, @as(isize, outfd)), + @bitCast(usize, @as(isize, infd)), + @ptrToInt(offset), + count, + ); + } +} + pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { if (builtin.arch == .i386) { return socketcall(SC_socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]) }); |
