mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
Merge pull request #5856 from A1029384756/master
[core:os/os2] zeroed `n` value on failed file operations
This commit is contained in:
@@ -198,7 +198,7 @@ _seek :: proc(f: ^File_Impl, offset: i64, whence: io.Seek_From) -> (ret: i64, er
|
|||||||
case .NONE:
|
case .NONE:
|
||||||
return n, nil
|
return n, nil
|
||||||
case:
|
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)])
|
n, errno := linux.read(f.fd, p[:min(len(p), MAX_RW)])
|
||||||
if errno != .NONE {
|
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
|
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)
|
n, errno := linux.pread(f.fd, p[:min(len(p), MAX_RW)], offset)
|
||||||
if errno != .NONE {
|
if errno != .NONE {
|
||||||
return -1, _get_platform_error(errno)
|
return 0, _get_platform_error(errno)
|
||||||
}
|
}
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return 0, .EOF
|
return 0, .EOF
|
||||||
@@ -276,7 +276,7 @@ _file_size :: proc(f: ^File_Impl) -> (n: i64, err: Error) {
|
|||||||
s: linux.Stat = ---
|
s: linux.Stat = ---
|
||||||
errno := linux.fstat(f.fd, &s)
|
errno := linux.fstat(f.fd, &s)
|
||||||
if errno != .NONE {
|
if errno != .NONE {
|
||||||
return -1, _get_platform_error(errno)
|
return 0, _get_platform_error(errno)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.mode & linux.S_IFMT == linux.S_IFREG {
|
if s.mode & linux.S_IFMT == linux.S_IFREG {
|
||||||
|
|||||||
@@ -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))
|
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 {
|
switch {
|
||||||
case n == 0:
|
case _n == 0:
|
||||||
err = .EOF
|
err = .EOF
|
||||||
case n < 0:
|
case _n < 0:
|
||||||
err = .Unknown
|
err = .Unknown
|
||||||
|
case:
|
||||||
|
n = _n
|
||||||
}
|
}
|
||||||
return
|
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))
|
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 {
|
switch {
|
||||||
case n == 0:
|
case _n == 0:
|
||||||
err = .EOF
|
err = .EOF
|
||||||
case n < 0:
|
case _n < 0:
|
||||||
err = .Unknown
|
err = .Unknown
|
||||||
|
case:
|
||||||
|
n = _n
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -460,15 +464,18 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
n = i64(posix.lseek(fd, posix.off_t(offset), posix.Whence(whence)))
|
_n := i64(posix.lseek(fd, posix.off_t(offset), posix.Whence(whence)))
|
||||||
if n < 0 {
|
if _n < 0 {
|
||||||
#partial switch posix.get_errno() {
|
#partial switch posix.get_errno() {
|
||||||
case .EINVAL:
|
case .EINVAL:
|
||||||
err = .Invalid_Offset
|
err = .Invalid_Offset
|
||||||
case:
|
case:
|
||||||
err = .Unknown
|
err = .Unknown
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n = _n
|
||||||
return
|
return
|
||||||
|
|
||||||
case .Size:
|
case .Size:
|
||||||
|
|||||||
Reference in New Issue
Block a user