Merge pull request #5856 from A1029384756/master

[core:os/os2] zeroed `n` value on failed file operations
This commit is contained in:
Laytan
2025-10-27 18:05:38 +01:00
committed by GitHub
2 changed files with 19 additions and 12 deletions

View File

@@ -198,7 +198,7 @@ _seek :: proc(f: ^File_Impl, offset: i64, whence: io.Seek_From) -> (ret: i64, er
case .NONE:
return n, nil
case:
return -1, _get_platform_error(errno)
return 0, _get_platform_error(errno)
}
}
@@ -209,7 +209,7 @@ _read :: proc(f: ^File_Impl, p: []byte) -> (i64, Error) {
n, errno := linux.read(f.fd, p[:min(len(p), MAX_RW)])
if errno != .NONE {
return -1, _get_platform_error(errno)
return 0, _get_platform_error(errno)
}
return i64(n), io.Error.EOF if n == 0 else nil
}
@@ -223,7 +223,7 @@ _read_at :: proc(f: ^File_Impl, p: []byte, offset: i64) -> (i64, Error) {
}
n, errno := linux.pread(f.fd, p[:min(len(p), MAX_RW)], offset)
if errno != .NONE {
return -1, _get_platform_error(errno)
return 0, _get_platform_error(errno)
}
if n == 0 {
return 0, .EOF
@@ -276,7 +276,7 @@ _file_size :: proc(f: ^File_Impl) -> (n: i64, err: Error) {
s: linux.Stat = ---
errno := linux.fstat(f.fd, &s)
if errno != .NONE {
return -1, _get_platform_error(errno)
return 0, _get_platform_error(errno)
}
if s.mode & linux.S_IFMT == linux.S_IFREG {

View File

@@ -382,12 +382,14 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
}
to_read := uint(min(len(p), MAX_RW))
n = i64(posix.read(fd, raw_data(p), to_read))
_n := i64(posix.read(fd, raw_data(p), to_read))
switch {
case n == 0:
case _n == 0:
err = .EOF
case n < 0:
case _n < 0:
err = .Unknown
case:
n = _n
}
return
@@ -402,12 +404,14 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
}
to_read := uint(min(len(p), MAX_RW))
n = i64(posix.pread(fd, raw_data(p), to_read, posix.off_t(offset)))
_n := i64(posix.pread(fd, raw_data(p), to_read, posix.off_t(offset)))
switch {
case n == 0:
case _n == 0:
err = .EOF
case n < 0:
case _n < 0:
err = .Unknown
case:
n = _n
}
return
@@ -460,15 +464,18 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
return
}
n = i64(posix.lseek(fd, posix.off_t(offset), posix.Whence(whence)))
if n < 0 {
_n := i64(posix.lseek(fd, posix.off_t(offset), posix.Whence(whence)))
if _n < 0 {
#partial switch posix.get_errno() {
case .EINVAL:
err = .Invalid_Offset
case:
err = .Unknown
}
return
}
n = _n
return
case .Size: