mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 04:50:29 +00:00
prevent infinite-loop on EOF
This commit is contained in:
@@ -243,11 +243,6 @@ pread :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
||||
if !win32.ReadFile(h, raw_data(buf), u32(len(buf)), &done, &o) {
|
||||
e = Errno(win32.GetLastError())
|
||||
done = 0
|
||||
|
||||
// this makes behavior between *nix and windows consistent when EOF is hit
|
||||
if e == ERROR_EOF {
|
||||
e = 0
|
||||
}
|
||||
}
|
||||
return int(done), e
|
||||
}
|
||||
@@ -292,6 +287,10 @@ read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Errno) {
|
||||
b, offset := data, offset
|
||||
for len(b) > 0 {
|
||||
m, e := pread(fd, b, offset)
|
||||
if e == ERROR_EOF {
|
||||
err = 0
|
||||
break
|
||||
}
|
||||
if e != 0 {
|
||||
err = e
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user