aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-08-04 15:07:24 +0100
committergingerBill <bill@gingerbill.org>2024-08-04 15:07:24 +0100
commitbf948ab8aed9099cf17beb91bf75b07698661a51 (patch)
treef2e5afeecbeb14114c01e3ed377db28babcc200a
parentacb1ebddf68d4611f666aa3c85ec1c28f40fafbe (diff)
Add stubs for `flush` on platforms that didn't have it
-rw-r--r--core/os/os_essence.odin5
-rw-r--r--core/os/os_freebsd.odin5
-rw-r--r--core/os/os_haiku.odin5
-rw-r--r--core/os/os_linux.odin5
-rw-r--r--core/os/os_netbsd.odin5
-rw-r--r--core/os/os_openbsd.odin5
-rw-r--r--core/os/os_wasi.odin6
-rw-r--r--core/os/stream.odin8
8 files changed, 38 insertions, 6 deletions
diff --git a/core/os/os_essence.odin b/core/os/os_essence.odin
index 71708cfbb..75c4c1156 100644
--- a/core/os/os_essence.odin
+++ b/core/os/os_essence.odin
@@ -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
+} \ No newline at end of file
diff --git a/core/os/os_freebsd.odin b/core/os/os_freebsd.odin
index 3c514084e..1a38aa20c 100644
--- a/core/os/os_freebsd.odin
+++ b/core/os/os_freebsd.odin
@@ -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
diff --git a/core/os/os_haiku.odin b/core/os/os_haiku.odin
index 9adca340c..ffaf12aae 100644
--- a/core/os/os_haiku.odin
+++ b/core/os/os_haiku.odin
@@ -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.
diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin
index 267ba3330..4aa4f279e 100644
--- a/core/os/os_linux.odin
+++ b/core/os/os_linux.odin
@@ -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,
diff --git a/core/os/os_netbsd.odin b/core/os/os_netbsd.odin
index 69d0cab8a..7905a7d4e 100644
--- a/core/os/os_netbsd.odin
+++ b/core/os/os_netbsd.odin
@@ -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
diff --git a/core/os/os_openbsd.odin b/core/os/os_openbsd.odin
index 30ffb3432..1c2e652b0 100644
--- a/core/os/os_openbsd.odin
+++ b/core/os/os_openbsd.odin
@@ -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
diff --git a/core/os/os_wasi.odin b/core/os/os_wasi.odin
index 9da053796..992c00f21 100644
--- a/core/os/os_wasi.odin
+++ b/core/os/os_wasi.odin
@@ -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)
diff --git a/core/os/stream.odin b/core/os/stream.odin
index cb392ccaf..8acbee489 100644
--- a/core/os/stream.odin
+++ b/core/os/stream.odin
@@ -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)