mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
Return 0, nil in all io cases where an empty slice is provided
This commit is contained in:
@@ -144,6 +144,9 @@ buffer_grow :: proc(b: ^Buffer, n: int, loc := #caller_location) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer_write_at :: proc(b: ^Buffer, p: []byte, offset: int, loc := #caller_location) -> (n: int, err: io.Error) {
|
buffer_write_at :: proc(b: ^Buffer, p: []byte, offset: int, loc := #caller_location) -> (n: int, err: io.Error) {
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
b.last_read = .Invalid
|
b.last_read = .Invalid
|
||||||
if offset < 0 {
|
if offset < 0 {
|
||||||
err = .Invalid_Offset
|
err = .Invalid_Offset
|
||||||
@@ -246,6 +249,9 @@ buffer_read_ptr :: proc(b: ^Buffer, ptr: rawptr, size: int) -> (n: int, err: io.
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer_read_at :: proc(b: ^Buffer, p: []byte, offset: int) -> (n: int, err: io.Error) {
|
buffer_read_at :: proc(b: ^Buffer, p: []byte, offset: int) -> (n: int, err: io.Error) {
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
b.last_read = .Invalid
|
b.last_read = .Invalid
|
||||||
|
|
||||||
if uint(offset) >= len(b.buf) {
|
if uint(offset) >= len(b.buf) {
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ reader_size :: proc(r: ^Reader) -> i64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reader_read :: proc(r: ^Reader, p: []byte) -> (n: int, err: io.Error) {
|
reader_read :: proc(r: ^Reader, p: []byte) -> (n: int, err: io.Error) {
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
if r.i >= i64(len(r.s)) {
|
if r.i >= i64(len(r.s)) {
|
||||||
return 0, .EOF
|
return 0, .EOF
|
||||||
}
|
}
|
||||||
@@ -43,6 +46,9 @@ reader_read :: proc(r: ^Reader, p: []byte) -> (n: int, err: io.Error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
reader_read_at :: proc(r: ^Reader, p: []byte, off: i64) -> (n: int, err: io.Error) {
|
reader_read_at :: proc(r: ^Reader, p: []byte, off: i64) -> (n: int, err: io.Error) {
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
if off < 0 {
|
if off < 0 {
|
||||||
return 0, .Invalid_Offset
|
return 0, .Invalid_Offset
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -340,6 +340,9 @@ _limited_reader_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []byte,
|
|||||||
l := (^Limited_Reader)(stream_data)
|
l := (^Limited_Reader)(stream_data)
|
||||||
#partial switch mode {
|
#partial switch mode {
|
||||||
case .Read:
|
case .Read:
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
if l.n <= 0 {
|
if l.n <= 0 {
|
||||||
return 0, .EOF
|
return 0, .EOF
|
||||||
}
|
}
|
||||||
@@ -394,6 +397,9 @@ _section_reader_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []byte,
|
|||||||
s := (^Section_Reader)(stream_data)
|
s := (^Section_Reader)(stream_data)
|
||||||
#partial switch mode {
|
#partial switch mode {
|
||||||
case .Read:
|
case .Read:
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
if s.off >= s.limit {
|
if s.off >= s.limit {
|
||||||
return 0, .EOF
|
return 0, .EOF
|
||||||
}
|
}
|
||||||
@@ -405,6 +411,9 @@ _section_reader_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []byte,
|
|||||||
s.off += i64(n)
|
s.off += i64(n)
|
||||||
return
|
return
|
||||||
case .Read_At:
|
case .Read_At:
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
p, off := p, offset
|
p, off := p, offset
|
||||||
|
|
||||||
if off < 0 || off >= s.limit - s.base {
|
if off < 0 || off >= s.limit - s.base {
|
||||||
|
|||||||
@@ -201,6 +201,9 @@ _read :: proc(f: ^File_Impl, p: []byte) -> (i64, Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_read_at :: proc(f: ^File_Impl, p: []byte, offset: i64) -> (i64, Error) {
|
_read_at :: proc(f: ^File_Impl, p: []byte, offset: i64) -> (i64, Error) {
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
if offset < 0 {
|
if offset < 0 {
|
||||||
return 0, .Invalid_Offset
|
return 0, .Invalid_Offset
|
||||||
}
|
}
|
||||||
@@ -226,6 +229,9 @@ _write :: proc(f: ^File_Impl, p: []byte) -> (i64, Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_write_at :: proc(f: ^File_Impl, p: []byte, offset: i64) -> (i64, Error) {
|
_write_at :: proc(f: ^File_Impl, p: []byte, offset: i64) -> (i64, Error) {
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
if offset < 0 {
|
if offset < 0 {
|
||||||
return 0, .Invalid_Offset
|
return 0, .Invalid_Offset
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,6 +266,11 @@ _read :: proc(f: ^File_Impl, p: []byte) -> (n: i64, err: Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_read_internal :: proc(f: ^File_Impl, p: []byte) -> (n: i64, err: Error) {
|
_read_internal :: proc(f: ^File_Impl, p: []byte) -> (n: i64, err: Error) {
|
||||||
|
length := len(p)
|
||||||
|
if length == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
read_console :: proc(handle: win32.HANDLE, b: []byte) -> (n: int, err: Error) {
|
read_console :: proc(handle: win32.HANDLE, b: []byte) -> (n: int, err: Error) {
|
||||||
if len(b) == 0 {
|
if len(b) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
@@ -320,7 +325,6 @@ _read_internal :: proc(f: ^File_Impl, p: []byte) -> (n: i64, err: Error) {
|
|||||||
|
|
||||||
single_read_length: win32.DWORD
|
single_read_length: win32.DWORD
|
||||||
total_read: int
|
total_read: int
|
||||||
length := len(p)
|
|
||||||
|
|
||||||
sync.shared_guard(&f.rw_mutex) // multiple readers
|
sync.shared_guard(&f.rw_mutex) // multiple readers
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
|
|||||||
case .Flush:
|
case .Flush:
|
||||||
os_err = flush(fd)
|
os_err = flush(fd)
|
||||||
case .Read:
|
case .Read:
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
n_int, os_err = read(fd, p)
|
n_int, os_err = read(fd, p)
|
||||||
n = i64(n_int)
|
n = i64(n_int)
|
||||||
if n == 0 && os_err == nil {
|
if n == 0 && os_err == nil {
|
||||||
@@ -28,18 +31,27 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case .Read_At:
|
case .Read_At:
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
n_int, os_err = read_at(fd, p, offset)
|
n_int, os_err = read_at(fd, p, offset)
|
||||||
n = i64(n_int)
|
n = i64(n_int)
|
||||||
if n == 0 && os_err == nil {
|
if n == 0 && os_err == nil {
|
||||||
err = .EOF
|
err = .EOF
|
||||||
}
|
}
|
||||||
case .Write:
|
case .Write:
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
n_int, os_err = write(fd, p)
|
n_int, os_err = write(fd, p)
|
||||||
n = i64(n_int)
|
n = i64(n_int)
|
||||||
if n == 0 && os_err == nil {
|
if n == 0 && os_err == nil {
|
||||||
err = .EOF
|
err = .EOF
|
||||||
}
|
}
|
||||||
case .Write_At:
|
case .Write_At:
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
n_int, os_err = write_at(fd, p, offset)
|
n_int, os_err = write_at(fd, p, offset)
|
||||||
n = i64(n_int)
|
n = i64(n_int)
|
||||||
if n == 0 && os_err == nil {
|
if n == 0 && os_err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user