Browse Source

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

gingerBill 1 year ago
parent
commit
bf948ab8ae

+ 5 - 0
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) {
 seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
 	return (i64) (0), (Error) (1)
 	return (i64) (0), (Error) (1)
 }
 }
+
+flush :: proc(fd: Handle) -> Error {
+	// do nothing
+	return nil
+}

+ 5 - 0
core/os/os_freebsd.odin

@@ -442,6 +442,11 @@ close :: proc(fd: Handle) -> Error {
 	return nil
 	return nil
 }
 }
 
 
+flush :: proc(fd: Handle) -> Error {
+	// do nothing
+	return nil
+}
+
 // If you read or write more than `INT_MAX` bytes, FreeBSD returns `EINVAL`.
 // 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,
 // 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
 // which is why the number of bytes is returned and why there are procs that will call this in a

+ 5 - 0
core/os/os_haiku.odin

@@ -212,6 +212,11 @@ close :: proc(fd: Handle) -> Error {
 	return nil
 	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,
 // 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
 // which is why the number of bytes is returned and why there are procs that will call this in a
 // loop for you.
 // loop for you.

+ 5 - 0
core/os/os_linux.odin

@@ -581,6 +581,11 @@ close :: proc(fd: Handle) -> Error {
 	return _get_errno(unix.sys_close(int(fd)))
 	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).
 // 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.
 // `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,
 // In practice a read/write call would probably never read/write these big buffers all at once,

+ 5 - 0
core/os/os_netbsd.odin

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

+ 5 - 0
core/os/os_openbsd.odin

@@ -426,6 +426,11 @@ close :: proc(fd: Handle) -> Error {
 	return nil
 	return nil
 }
 }
 
 
+flush :: proc(fd: Handle) -> Error {
+	// do nothing
+	return nil
+}
+
 // If you read or write more than `SSIZE_MAX` bytes, OpenBSD returns `EINVAL`.
 // 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,
 // 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
 // which is why the number of bytes is returned and why there are procs that will call this in a

+ 6 - 0
core/os/os_wasi.odin

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

+ 2 - 6
core/os/stream.odin

@@ -17,13 +17,9 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
 	os_err: Error
 	os_err: Error
 	switch mode {
 	switch mode {
 	case .Close:
 	case .Close:
-		close(fd)
+		os_err = close(fd)
 	case .Flush:
 	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:
 	case .Read:
 		n_int, os_err = read(fd, p)
 		n_int, os_err = read(fd, p)
 		n = i64(n_int)
 		n = i64(n_int)