parent
44d8d654a0
commit
40e4e42a66
|
@ -189,10 +189,15 @@ pub fn close(handle: FileHandle) void {
|
||||||
|
|
||||||
/// Calls POSIX read, and keeps trying if it gets interrupted.
|
/// Calls POSIX read, and keeps trying if it gets interrupted.
|
||||||
pub fn posixRead(fd: i32, buf: []u8) %void {
|
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;
|
var index: usize = 0;
|
||||||
while (index < buf.len) {
|
while (index < buf.len) {
|
||||||
const amt_written = posix.read(fd, &buf[index], buf.len - index);
|
const want_to_read = math.min(buf.len - index, usize(max_buf_len));
|
||||||
const err = posix.getErrno(amt_written);
|
const rc = posix.read(fd, &buf[index], want_to_read);
|
||||||
|
const err = posix.getErrno(rc);
|
||||||
if (err > 0) {
|
if (err > 0) {
|
||||||
return switch (err) {
|
return switch (err) {
|
||||||
posix.EINTR => continue,
|
posix.EINTR => continue,
|
||||||
|
@ -205,7 +210,7 @@ pub fn posixRead(fd: i32, buf: []u8) %void {
|
||||||
else => unexpectedErrorPosix(err),
|
else => unexpectedErrorPosix(err),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
index += amt_written;
|
index += rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue