zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 40e4e42a669a5312cf9400a5e96d6288b44be286 (tree)
parent 44d8d654a0ba463a1d4cf34d435c8422bfcd1c81
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Mon,  5 Feb 2018 12:47:59 -0500

handle linux returning EINVAL for large reads

see #743

Diffstat:
Mstd/os/index.zig | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/std/os/index.zig b/std/os/index.zig @@ -189,10 +189,15 @@ pub fn close(handle: FileHandle) void { /// Calls POSIX read, and keeps trying if it gets interrupted. pub fn posixRead(fd: i32, buf: []u8) %void { + // Linux can return EINVAL when read amount is > 0x7ffff000 + // See https://github.com/zig-lang/zig/pull/743#issuecomment-363158274 + const max_buf_len = 0x7ffff000; + var index: usize = 0; while (index < buf.len) { - const amt_written = posix.read(fd, &buf[index], buf.len - index); - const err = posix.getErrno(amt_written); + const want_to_read = math.min(buf.len - index, usize(max_buf_len)); + const rc = posix.read(fd, &buf[index], want_to_read); + const err = posix.getErrno(rc); if (err > 0) { return switch (err) { posix.EINTR => continue, @@ -205,7 +210,7 @@ pub fn posixRead(fd: i32, buf: []u8) %void { else => unexpectedErrorPosix(err), }; } - index += amt_written; + index += rc; } }