diff options
| author | Laytan <laytanlaats@hotmail.com> | 2025-12-20 20:57:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-20 20:57:59 +0100 |
| commit | d2429d5fd30a44b0f6b3e1957108959bb035d906 (patch) | |
| tree | 5ccafbdf2b516507d3bfbcf0969abc335210d25c | |
| parent | f2d66ca888d05a8c5b3dc89f059ba738c5a5a4c5 (diff) | |
| parent | 45a3cfa24578f539ee61fff9f32355b8964a69b4 (diff) | |
Merge pull request #6045 from laytan/fix-windows-read-console-stale-errors
os/os2: better fix for the stale errors
| -rw-r--r-- | core/os/os2/file_windows.odin | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/core/os/os2/file_windows.odin b/core/os/os2/file_windows.odin index 22574ab2f..7c075b7b1 100644 --- a/core/os/os2/file_windows.odin +++ b/core/os/os2/file_windows.odin @@ -364,34 +364,30 @@ _read_internal :: proc(f: ^File_Impl, p: []byte) -> (n: i64, err: Error) { handle := _handle(&f.file) - single_read_length: win32.DWORD total_read: int sync.shared_guard(&f.rw_mutex) // multiple readers if sync.guard(&f.p_mutex) { to_read := min(win32.DWORD(length), MAX_RW) - ok: win32.BOOL - if f.kind == .Console { - n, cerr := read_console(handle, p[total_read:][:to_read]) - total_read += n - if cerr != nil { - return i64(total_read), cerr + switch f.kind { + case .Console: + total_read, err = read_console(handle, p[total_read:][:to_read]) + case .Pipe, .File: + single_read_length: win32.DWORD + ok := win32.ReadFile(handle, &p[total_read], to_read, &single_read_length, nil) + if ok { + total_read += int(single_read_length) + } else { + err = _get_platform_error() } - ok = true - } else { - ok = win32.ReadFile(handle, &p[total_read], to_read, &single_read_length, nil) } + } - if single_read_length > 0 && ok { - total_read += int(single_read_length) - } else if single_read_length == 0 && ok { - // ok and 0 bytes means EOF: - // https://learn.microsoft.com/en-us/windows/win32/fileio/testing-for-the-end-of-a-file - err = .EOF - } else { - err = _get_platform_error() - } + if total_read == 0 && err == nil { + // ok and 0 bytes means EOF: + // https://learn.microsoft.com/en-us/windows/win32/fileio/testing-for-the-end-of-a-file + err = .EOF } return i64(total_read), err |