diff options
| author | gingerBill <bill@gingerbill.org> | 2022-02-25 12:02:41 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-02-25 12:02:41 +0000 |
| commit | 47c79a2f25270969bbc3b0faac54ba1888f67b9d (patch) | |
| tree | 2113348bcd2159686a6def9e25a2a6fd1c03454f | |
| parent | e81ed9a9601f6a7761dec5b0f96cc8680a16f166 (diff) | |
Correct `os.read` on windows for `os.stdin`
| -rw-r--r-- | core/os/file_windows.odin | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/core/os/file_windows.odin b/core/os/file_windows.odin index 8a0f2ed64..062e2b8a5 100644 --- a/core/os/file_windows.odin +++ b/core/os/file_windows.odin @@ -108,17 +108,18 @@ read_console :: proc(handle: win32.HANDLE, b: []byte) -> (n: int, err: Errno) { buf8: [4*BUF_SIZE]u8 for n < len(b) && err == 0 { - max_read := u32(min(BUF_SIZE, len(b)/4)) - + min_read := max(min(len(b), 4), len(b)/4) + max_read := u32(min(BUF_SIZE, min_read)) + single_read_length: u32 ok := win32.ReadConsoleW(handle, &buf16[0], max_read, &single_read_length, nil) if !ok { err = Errno(win32.GetLastError()) } - + buf8_len := utf16.decode_to_utf8(buf8[:], buf16[:single_read_length]) src := buf8[:buf8_len] - + ctrl_z := false for i := 0; i < len(src) && n+i < len(b); i += 1 { x := src[i] @@ -129,7 +130,7 @@ read_console :: proc(handle: win32.HANDLE, b: []byte) -> (n: int, err: Errno) { b[n] = x n += 1 } - if ctrl_z || single_read_length < len(buf16) { + if ctrl_z || single_read_length < max_read { break } } |