Browse Source

prevent infinite-loop on EOF

Colin Davidson 2 years ago
parent
commit
b0eda47b26
1 changed files with 4 additions and 5 deletions
  1. 4 5
      core/os/file_windows.odin

+ 4 - 5
core/os/file_windows.odin

@@ -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