mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Fix os.read for windows
This commit is contained in:
+14
-12
@@ -145,21 +145,23 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
|||||||
read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||||
if len(data) == 0 do return 0, ERROR_NONE;
|
if len(data) == 0 do return 0, ERROR_NONE;
|
||||||
|
|
||||||
read := 0;
|
single_read_length: u32;
|
||||||
for {
|
total_read: i64;
|
||||||
to_read := u32(min(1<<29-1, len(data)-read));
|
length := i64(len(data));
|
||||||
if to_read <= 0 do break;
|
|
||||||
|
|
||||||
n: u32;
|
for total_read < length {
|
||||||
ok := win32.read_file(win32.Handle(fd), &data[to_read], to_read, &n, nil);
|
remaining := length - total_read;
|
||||||
if !ok {
|
MAX :: 1<<31-1;
|
||||||
return int(read), Errno(win32.get_last_error());
|
to_read: u32 = min(u32(remaining), MAX);
|
||||||
|
|
||||||
|
e := win32.read_file(win32.Handle(fd), &data[total_read], to_read, &single_read_length, nil);
|
||||||
|
if !e {
|
||||||
|
err := Errno(win32.get_last_error());
|
||||||
|
return int(total_read), err;
|
||||||
}
|
}
|
||||||
|
total_read += i64(single_read_length);
|
||||||
read += int(n);
|
|
||||||
}
|
}
|
||||||
|
return int(total_read), ERROR_NONE;
|
||||||
return int(read), ERROR_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||||
|
|||||||
Reference in New Issue
Block a user