| ... | ... | @@ -442,33 +442,30 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo |
| 442 | 442 | } |
| 443 | 443 | return @as(usize, bytes_transferred); |
| 444 | 444 | } else { |
| 445 | | var index: usize = 0; |
| 446 | | while (index < buffer.len) { |
| 447 | | const want_read_count = @intCast(DWORD, math.min(@as(DWORD, maxInt(DWORD)), buffer.len - index)); |
| 445 | while (true) { |
| 446 | const want_read_count = @intCast(DWORD, math.min(@as(DWORD, maxInt(DWORD)), buffer.len)); |
| 448 | 447 | var amt_read: DWORD = undefined; |
| 449 | 448 | var overlapped_data: OVERLAPPED = undefined; |
| 450 | 449 | const overlapped: ?*OVERLAPPED = if (offset) |off| blk: { |
| 451 | 450 | overlapped_data = .{ |
| 452 | 451 | .Internal = 0, |
| 453 | 452 | .InternalHigh = 0, |
| 454 | | .Offset = @truncate(u32, off + index), |
| 455 | | .OffsetHigh = @truncate(u32, (off + index) >> 32), |
| 453 | .Offset = @truncate(u32, off), |
| 454 | .OffsetHigh = @truncate(u32, off >> 32), |
| 456 | 455 | .hEvent = null, |
| 457 | 456 | }; |
| 458 | 457 | break :blk &overlapped_data; |
| 459 | 458 | } else null; |
| 460 | | if (kernel32.ReadFile(in_hFile, buffer.ptr + index, want_read_count, &amt_read, overlapped) == 0) { |
| 459 | if (kernel32.ReadFile(in_hFile, buffer.ptr, want_read_count, &amt_read, overlapped) == 0) { |
| 461 | 460 | switch (kernel32.GetLastError()) { |
| 462 | 461 | .OPERATION_ABORTED => continue, |
| 463 | | .BROKEN_PIPE => return index, |
| 464 | | .HANDLE_EOF => return index, |
| 462 | .BROKEN_PIPE => return 0, |
| 463 | .HANDLE_EOF => return 0, |
| 465 | 464 | else => |err| return unexpectedError(err), |
| 466 | 465 | } |
| 467 | 466 | } |
| 468 | | if (amt_read == 0) return index; |
| 469 | | index += amt_read; |
| 467 | return amt_read; |
| 470 | 468 | } |
| 471 | | return index; |
| 472 | 469 | } |
| 473 | 470 | } |
| 474 | 471 | |