Add stubs for flush on platforms that didn't have it

This commit is contained in:
gingerBill
2024-08-04 15:07:24 +01:00
parent acb1ebddf6
commit bf948ab8ae
8 changed files with 38 additions and 6 deletions

View File

@@ -53,3 +53,8 @@ write :: proc(fd: Handle, data: []u8) -> (int, Error) {
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
return (i64) (0), (Error) (1)
}
flush :: proc(fd: Handle) -> Error {
// do nothing
return nil
}

View File

@@ -442,6 +442,11 @@ close :: proc(fd: Handle) -> Error {
return nil
}
flush :: proc(fd: Handle) -> Error {
// do nothing
return nil
}
// If you read or write more than `INT_MAX` bytes, FreeBSD returns `EINVAL`.
// In practice a read/write call would probably never read/write these big buffers all at once,
// which is why the number of bytes is returned and why there are procs that will call this in a

View File

@@ -212,6 +212,11 @@ close :: proc(fd: Handle) -> Error {
return nil
}
flush :: proc(fd: Handle) -> Error {
// do nothing
return nil
}
// In practice a read/write call would probably never read/write these big buffers all at once,
// which is why the number of bytes is returned and why there are procs that will call this in a
// loop for you.

View File

@@ -581,6 +581,11 @@ close :: proc(fd: Handle) -> Error {
return _get_errno(unix.sys_close(int(fd)))
}
flush :: proc(fd: Handle) -> Error {
// do nothing
return nil
}
// If you read or write more than `SSIZE_MAX` bytes, result is implementation defined (probably an error).
// `SSIZE_MAX` is also implementation defined but usually the max of a `ssize_t` which is `max(int)` in Odin.
// In practice a read/write call would probably never read/write these big buffers all at once,

View File

@@ -502,6 +502,11 @@ close :: proc(fd: Handle) -> Error {
return nil
}
flush :: proc(fd: Handle) -> Error {
// do nothing
return nil
}
// We set a max of 1GB to keep alignment and to be safe.
@(private)
MAX_RW :: 1 << 30

View File

@@ -426,6 +426,11 @@ close :: proc(fd: Handle) -> Error {
return nil
}
flush :: proc(fd: Handle) -> Error {
// do nothing
return nil
}
// If you read or write more than `SSIZE_MAX` bytes, OpenBSD returns `EINVAL`.
// In practice a read/write call would probably never read/write these big buffers all at once,
// which is why the number of bytes is returned and why there are procs that will call this in a

View File

@@ -205,6 +205,12 @@ close :: proc(fd: Handle) -> Errno {
err := wasi.fd_close(wasi.fd_t(fd))
return Platform_Error(err)
}
flush :: proc(fd: Handle) -> Error {
// do nothing
return nil
}
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
n, err := wasi.fd_seek(wasi.fd_t(fd), wasi.filedelta_t(offset), wasi.whence_t(whence))
return i64(n), Platform_Error(err)

View File

@@ -17,13 +17,9 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
os_err: Error
switch mode {
case .Close:
close(fd)
os_err = close(fd)
case .Flush:
when ODIN_OS == .Windows || ODIN_OS == .Darwin || ODIN_OS == .JS {
flush(fd)
} else {
// TOOD(bill): other operating systems
}
os_err = flush(fd)
case .Read:
n_int, os_err = read(fd, p)
n = i64(n_int)