Skip to content

Commit

Permalink
fix eof logic
Browse files Browse the repository at this point in the history
  • Loading branch information
laytan committed Dec 13, 2023
1 parent 203cb74 commit 54e6226
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions core/os/stream.odin
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,31 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
case .Read:
n_int, os_err = read(fd, p)
n = i64(n_int)
if n == 0 && os_err == 0 {
err = .EOF
}

case .Read_At:
when !(ODIN_OS == .FreeBSD || ODIN_OS == .OpenBSD) {
n_int, os_err = read_at(fd, p, offset)
n = i64(n_int)
if n == 0 && os_err == 0 {
err = .EOF
}
}
case .Write:
n_int, os_err = write(fd, p)
n = i64(n_int)
if n == 0 && os_err == 0 {
err = .EOF
}
case .Write_At:
when !(ODIN_OS == .FreeBSD || ODIN_OS == .OpenBSD) {
n_int, os_err = write_at(fd, p, offset)
n = i64(n_int)
if n == 0 && os_err == 0 {
err = .EOF
}
}
case .Seek:
n, os_err = seek(fd, offset, int(whence))
Expand All @@ -63,12 +75,5 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
}
err = .Unknown
}

when ODIN_OS != .Windows {
if err == nil && os_err == 0 && n == 0 {
err = .EOF
}
}

return
}

0 comments on commit 54e6226

Please sign in to comment.