| ... | @@ -225,9 +225,15 @@ error BrokenPipe; | ... | @@ -225,9 +225,15 @@ error BrokenPipe; |
| 225 | | 225 | |
| 226 | /// Calls POSIX write, and keeps trying if it gets interrupted. | 226 | /// Calls POSIX write, and keeps trying if it gets interrupted. |
| 227 | pub fn posixWrite(fd: i32, bytes: []const u8) %void { | 227 | pub fn posixWrite(fd: i32, bytes: []const u8) %void { |
| 228 | while (true) { | 228 | // Linux can return EINVAL when write amount is > 0x7ffff000 |
| 229 | const write_ret = posix.write(fd, bytes.ptr, bytes.len); | 229 | // See https://github.com/zig-lang/zig/pull/743#issuecomment-363165856 |
| 230 | const write_err = posix.getErrno(write_ret); | 230 | const max_bytes_len = 0x7ffff000; |
| | 231 | |
| | 232 | var index: usize = 0; |
| | 233 | while (index < bytes.len) { |
| | 234 | const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len)); |
| | 235 | const rc = posix.write(fd, &bytes[index], amt_to_write); |
| | 236 | const write_err = posix.getErrno(rc); |
| 231 | if (write_err > 0) { | 237 | if (write_err > 0) { |
| 232 | return switch (write_err) { | 238 | return switch (write_err) { |
| 233 | posix.EINTR => continue, | 239 | posix.EINTR => continue, |
| ... | @@ -244,7 +250,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) %void { | ... | @@ -244,7 +250,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) %void { |
| 244 | else => unexpectedErrorPosix(write_err), | 250 | else => unexpectedErrorPosix(write_err), |
| 245 | }; | 251 | }; |
| 246 | } | 252 | } |
| 247 | return; | 253 | index += rc; |
| 248 | } | 254 | } |
| 249 | } | 255 | } |
| 250 | | 256 | |