aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorlaytan <laytanlaats@hotmail.com>2025-12-20 19:33:17 +0100
committerlaytan <laytanlaats@hotmail.com>2025-12-20 19:45:45 +0100
commit45a3cfa24578f539ee61fff9f32355b8964a69b4 (patch)
tree5ccafbdf2b516507d3bfbcf0969abc335210d25c /core
parentca1bb09e97555c6324a1c86720ee9b666a73de71 (diff)
os/os2: better fix for the stale errors
Diffstat (limited to 'core')
-rw-r--r--core/os/os2/file_windows.odin34
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