mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
Fix FreeBSD implementations of read_at and write_at
These procedures must not modify the underlying file pointer.
This commit is contained in:
+17
-12
@@ -6,6 +6,7 @@ foreign import libc "system:c"
|
||||
import "base:runtime"
|
||||
import "core:strings"
|
||||
import "core:c"
|
||||
import "core:sys/freebsd"
|
||||
|
||||
Handle :: distinct i32
|
||||
File_Time :: distinct u64
|
||||
@@ -481,23 +482,27 @@ write :: proc(fd: Handle, data: []byte) -> (int, Error) {
|
||||
}
|
||||
|
||||
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Error) {
|
||||
curr := seek(fd, offset, SEEK_CUR) or_return
|
||||
n, err = read(fd, data)
|
||||
_, err1 := seek(fd, curr, SEEK_SET)
|
||||
if err1 != nil && err == nil {
|
||||
err = err1
|
||||
if len(data) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return
|
||||
|
||||
to_read := min(uint(len(data)), MAX_RW)
|
||||
|
||||
bytes_read, errno := freebsd.pread(cast(freebsd.Fd)fd, data[:to_read], cast(freebsd.off_t)offset)
|
||||
|
||||
return bytes_read, cast(_Platform_Error)errno
|
||||
}
|
||||
|
||||
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Error) {
|
||||
curr := seek(fd, offset, SEEK_CUR) or_return
|
||||
n, err = write(fd, data)
|
||||
_, err1 := seek(fd, curr, SEEK_SET)
|
||||
if err1 != nil && err == nil {
|
||||
err = err1
|
||||
if len(data) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return
|
||||
|
||||
to_write := min(uint(len(data)), MAX_RW)
|
||||
|
||||
bytes_written, errno := freebsd.pwrite(cast(freebsd.Fd)fd, data[:to_write], cast(freebsd.off_t)offset)
|
||||
|
||||
return bytes_written, cast(_Platform_Error)errno
|
||||
}
|
||||
|
||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
|
||||
|
||||
Reference in New Issue
Block a user