| ... | ... | @@ -189,10 +189,15 @@ pub fn close(handle: FileHandle) void { |
| 189 | 189 | |
| 190 | 190 | /// Calls POSIX read, and keeps trying if it gets interrupted. |
| 191 | 191 | pub fn posixRead(fd: i32, buf: []u8) %void { |
| 192 | // Linux can return EINVAL when read amount is > 0x7ffff000 |
| 193 | // See https://github.com/zig-lang/zig/pull/743#issuecomment-363158274 |
| 194 | const max_buf_len = 0x7ffff000; |
| 195 | |
| 192 | 196 | var index: usize = 0; |
| 193 | 197 | while (index < buf.len) { |
| 194 | | const amt_written = posix.read(fd, &buf[index], buf.len - index); |
| 195 | | const err = posix.getErrno(amt_written); |
| 198 | const want_to_read = math.min(buf.len - index, usize(max_buf_len)); |
| 199 | const rc = posix.read(fd, &buf[index], want_to_read); |
| 200 | const err = posix.getErrno(rc); |
| 196 | 201 | if (err > 0) { |
| 197 | 202 | return switch (err) { |
| 198 | 203 | posix.EINTR => continue, |
| ... | ... | @@ -205,7 +210,7 @@ pub fn posixRead(fd: i32, buf: []u8) %void { |
| 205 | 210 | else => unexpectedErrorPosix(err), |
| 206 | 211 | }; |
| 207 | 212 | } |
| 208 | | index += amt_written; |
| 213 | index += rc; |
| 209 | 214 | } |
| 210 | 215 | } |
| 211 | 216 | |