hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 93dc63b9b7373ca3038901fdeef4785332bdc8e4
parent 1f92c4b1c70f3ff213662e7b30ef40b5a70acce4
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat, 21 Sep 2024 10:28:22 +0200

Add io::fsync, io::fdatasync

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Aio/+freebsd/sync.ha | 32++++++++++++++++++++++++++++++++
Aio/+linux/sync.ha | 32++++++++++++++++++++++++++++++++
Aio/+netbsd/sync.ha | 32++++++++++++++++++++++++++++++++
Aio/+openbsd/sync.ha | 32++++++++++++++++++++++++++++++++
Mmakefiles/freebsd.aarch64.mk | 2+-
Mmakefiles/freebsd.riscv64.mk | 2+-
Mmakefiles/freebsd.x86_64.mk | 2+-
Mmakefiles/linux.aarch64.mk | 2+-
Mmakefiles/linux.riscv64.mk | 2+-
Mmakefiles/linux.x86_64.mk | 2+-
Mmakefiles/netbsd.aarch64.mk | 2+-
Mmakefiles/netbsd.riscv64.mk | 2+-
Mmakefiles/netbsd.x86_64.mk | 2+-
Mmakefiles/openbsd.aarch64.mk | 2+-
Mmakefiles/openbsd.riscv64.mk | 2+-
Mmakefiles/openbsd.x86_64.mk | 2+-
Mrt/+freebsd/syscalls.ha | 8++++++++
Mrt/+linux/syscalls.ha | 8++++++++
Mrt/+netbsd/syscalls.ha | 8++++++++
Mrt/+openbsd/syscalls.ha | 22++++++++++++++++++++++
20 files changed, 186 insertions(+), 12 deletions(-)

diff --git a/io/+freebsd/sync.ha b/io/+freebsd/sync.ha @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MPL-2.0 +// (c) Hare authors <https://harelang.org> + +use errors; +use rt; + +// Flushes all in-flight I/O for the given file descriptor to persistent +// storage, flushing any writes the kernel has cached, and any changes to the +// corresponding inode. +export fn fsync(fd: file) (void | error) = { + match (rt::fsync(fd)) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; + +// Flushes all in-flight I/O for the given file descriptor to persistent +// storage, flushing any writes the kernel has cached. Only persists changes to +// the associated inode if it is not required for the file contents to be +// successfully retrieved. If the file size has changed, for example, this will +// block until the inode is updated; but it would not block on an update to its +// mtime. +export fn fdatasync(fd: file) (void | error) = { + match (rt::fdatasync(fd)) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; diff --git a/io/+linux/sync.ha b/io/+linux/sync.ha @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MPL-2.0 +// (c) Hare authors <https://harelang.org> + +use errors; +use rt; + +// Flushes all in-flight I/O for the given file descriptor to persistent +// storage, flushing any writes the kernel has cached, and any changes to the +// corresponding inode. +export fn fsync(fd: file) (void | error) = { + match (rt::fsync(fd)) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; + +// Flushes all in-flight I/O for the given file descriptor to persistent +// storage, flushing any writes the kernel has cached. Only persists changes to +// the associated inode if it is not required for the file contents to be +// successfully retrieved. If the file size has changed, for example, this will +// block until the inode is updated; but it would not block on an update to its +// mtime. +export fn fdatasync(fd: file) (void | error) = { + match (rt::fdatasync(fd)) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; diff --git a/io/+netbsd/sync.ha b/io/+netbsd/sync.ha @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MPL-2.0 +// (c) Hare authors <https://harelang.org> + +use errors; +use rt; + +// Flushes all in-flight I/O for the given file descriptor to persistent +// storage, flushing any writes the kernel has cached, and any changes to the +// corresponding inode. +export fn fsync(fd: file) (void | error) = { + match (rt::fsync(fd)) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; + +// Flushes all in-flight I/O for the given file descriptor to persistent +// storage, flushing any writes the kernel has cached. Only persists changes to +// the associated inode if it is not required for the file contents to be +// successfully retrieved. If the file size has changed, for example, this will +// block until the inode is updated; but it would not block on an update to its +// mtime. +export fn fdatasync(fd: file) (void | error) = { + match (rt::fdatasync(fd)) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; diff --git a/io/+openbsd/sync.ha b/io/+openbsd/sync.ha @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MPL-2.0 +// (c) Hare authors <https://harelang.org> + +use errors; +use rt; + +// Flushes all in-flight I/O for the given file descriptor to persistent +// storage, flushing any writes the kernel has cached, and any changes to the +// corresponding inode. +export fn fsync(fd: file) (void | error) = { + match (rt::fsync(fd)) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; + +// Flushes all in-flight I/O for the given file descriptor to persistent +// storage, flushing any writes the kernel has cached. Only persists changes to +// the associated inode if it is not required for the file contents to be +// successfully retrieved. If the file size has changed, for example, this will +// block until the inode is updated; but it would not block on an update to its +// mtime. +export fn fdatasync(fd: file) (void | error) = { + match (rt::fdatasync(fd)) { + case let err: rt::errno => + return errors::errno(err); + case void => + return; + }; +}; diff --git a/makefiles/freebsd.aarch64.mk b/makefiles/freebsd.aarch64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+freebsd/dup.ha io/+freebsd/mmap.ha io/+freebsd/platform_file.ha io/+freebsd/vector.ha io/arch+aarch64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+freebsd/dup.ha io/+freebsd/mmap.ha io/+freebsd/platform_file.ha io/+freebsd/sync.ha io/+freebsd/vector.ha io/arch+aarch64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/makefiles/freebsd.riscv64.mk b/makefiles/freebsd.riscv64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+freebsd/dup.ha io/+freebsd/mmap.ha io/+freebsd/platform_file.ha io/+freebsd/vector.ha io/arch+riscv64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+freebsd/dup.ha io/+freebsd/mmap.ha io/+freebsd/platform_file.ha io/+freebsd/sync.ha io/+freebsd/vector.ha io/arch+riscv64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/makefiles/freebsd.x86_64.mk b/makefiles/freebsd.x86_64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+freebsd/dup.ha io/+freebsd/mmap.ha io/+freebsd/platform_file.ha io/+freebsd/vector.ha io/arch+x86_64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+freebsd/dup.ha io/+freebsd/mmap.ha io/+freebsd/platform_file.ha io/+freebsd/sync.ha io/+freebsd/vector.ha io/arch+x86_64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/makefiles/linux.aarch64.mk b/makefiles/linux.aarch64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+linux/dup.ha io/+linux/mmap.ha io/+linux/platform_file.ha io/+linux/vector.ha io/arch+aarch64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+linux/dup.ha io/+linux/mmap.ha io/+linux/platform_file.ha io/+linux/sync.ha io/+linux/vector.ha io/arch+aarch64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/makefiles/linux.riscv64.mk b/makefiles/linux.riscv64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+linux/dup.ha io/+linux/mmap.ha io/+linux/platform_file.ha io/+linux/vector.ha io/arch+riscv64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+linux/dup.ha io/+linux/mmap.ha io/+linux/platform_file.ha io/+linux/sync.ha io/+linux/vector.ha io/arch+riscv64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/makefiles/linux.x86_64.mk b/makefiles/linux.x86_64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+linux/dup.ha io/+linux/mmap.ha io/+linux/platform_file.ha io/+linux/vector.ha io/arch+x86_64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+linux/dup.ha io/+linux/mmap.ha io/+linux/platform_file.ha io/+linux/sync.ha io/+linux/vector.ha io/arch+x86_64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/makefiles/netbsd.aarch64.mk b/makefiles/netbsd.aarch64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+netbsd/dup.ha io/+netbsd/mmap.ha io/+netbsd/platform_file.ha io/+netbsd/vector.ha io/arch+aarch64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+netbsd/dup.ha io/+netbsd/mmap.ha io/+netbsd/platform_file.ha io/+netbsd/sync.ha io/+netbsd/vector.ha io/arch+aarch64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/makefiles/netbsd.riscv64.mk b/makefiles/netbsd.riscv64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+netbsd/dup.ha io/+netbsd/mmap.ha io/+netbsd/platform_file.ha io/+netbsd/vector.ha io/arch+riscv64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+netbsd/dup.ha io/+netbsd/mmap.ha io/+netbsd/platform_file.ha io/+netbsd/sync.ha io/+netbsd/vector.ha io/arch+riscv64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/makefiles/netbsd.x86_64.mk b/makefiles/netbsd.x86_64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+netbsd/dup.ha io/+netbsd/mmap.ha io/+netbsd/platform_file.ha io/+netbsd/vector.ha io/arch+x86_64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+netbsd/dup.ha io/+netbsd/mmap.ha io/+netbsd/platform_file.ha io/+netbsd/sync.ha io/+netbsd/vector.ha io/arch+x86_64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/makefiles/openbsd.aarch64.mk b/makefiles/openbsd.aarch64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+openbsd/dup.ha io/+openbsd/mmap.ha io/+openbsd/platform_file.ha io/+openbsd/vector.ha io/arch+aarch64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+openbsd/dup.ha io/+openbsd/mmap.ha io/+openbsd/platform_file.ha io/+openbsd/sync.ha io/+openbsd/vector.ha io/arch+aarch64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/makefiles/openbsd.riscv64.mk b/makefiles/openbsd.riscv64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+openbsd/dup.ha io/+openbsd/mmap.ha io/+openbsd/platform_file.ha io/+openbsd/vector.ha io/arch+riscv64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+openbsd/dup.ha io/+openbsd/mmap.ha io/+openbsd/platform_file.ha io/+openbsd/sync.ha io/+openbsd/vector.ha io/arch+riscv64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/makefiles/openbsd.x86_64.mk b/makefiles/openbsd.x86_64.mk @@ -57,7 +57,7 @@ $(HARECACHE)/errors.ssa: $(errors_ha) $(HARECACHE)/rt.td @printf 'HAREC\t%s\n' "$@" @$(TDENV) $(HAREC) $(HARECFLAGS) -o $@ -t $(HARECACHE)/errors.td.tmp -N errors $(errors_ha) -io_ha = io/+openbsd/dup.ha io/+openbsd/mmap.ha io/+openbsd/platform_file.ha io/+openbsd/vector.ha io/arch+x86_64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha +io_ha = io/+openbsd/dup.ha io/+openbsd/mmap.ha io/+openbsd/platform_file.ha io/+openbsd/sync.ha io/+openbsd/vector.ha io/arch+x86_64.ha io/copy.ha io/drain.ha io/empty.ha io/file.ha io/handle.ha io/limit.ha io/stream.ha io/tee.ha io/types.ha io/util.ha io/zero.ha $(HARECACHE)/io.ssa: $(io_ha) $(HARECACHE)/bytes.td $(HARECACHE)/errors.td $(HARECACHE)/rt.td $(HARECACHE)/types.td @mkdir -p -- "$(HARECACHE)" @printf 'HAREC\t%s\n' "$@" diff --git a/rt/+freebsd/syscalls.ha b/rt/+freebsd/syscalls.ha @@ -658,3 +658,11 @@ export fn shutdown(sockfd: int, how: int) (void | errno) = { wrap_return(syscall2(SYS_shutdown, sockfd: u64, how: u64))?; }; + +export fn fsync(fd: int) (void | errno) = { + wrap_return(syscall1(SYS_fsync, fd: u64))?; +}; + +export fn fdatasync(fd: int) (void | errno) = { + wrap_return(syscall1(SYS_fdatasync, fd: u64))?; +}; diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -1085,3 +1085,11 @@ export fn removexattr(path: path, name: str) (void | errno) = { wrap_return(syscall2(SYS_removexattr, path: uintptr, name: uintptr))?; }; + +export fn fsync(fd: int) (void | errno) = { + wrap_return(syscall1(SYS_fsync, fd: u64))?; +}; + +export fn fdatasync(fd: int) (void | errno) = { + wrap_return(syscall1(SYS_fdatasync, fd: u64))?; +}; diff --git a/rt/+netbsd/syscalls.ha b/rt/+netbsd/syscalls.ha @@ -627,3 +627,11 @@ export fn socketpair( return wrap_return(syscall4(SYS_socketpair, domain: u64, type_: u64, protocol: u64, sv: uintptr : u64))?: int; }; + +export fn fsync(fd: int) (void | errno) = { + wrap_return(syscall1(SYS_fsync, fd: u64))?; +}; + +export fn fdatasync(fd: int) (void | errno) = { + wrap_return(syscall1(SYS_fdatasync, fd: u64))?; +}; diff --git a/rt/+openbsd/syscalls.ha b/rt/+openbsd/syscalls.ha @@ -713,7 +713,29 @@ export fn accept4( }; // __thrsleep + // fsync +@symbol("fsync") fn libc_fsync(fd: int) int; + +export fn fsync(fd: int) (void | errno) = { + let res = libc_fsync(fd); + if (res == -1) { + return *__errno(): errno; + }; + return res; +}; + +// fdatasync +@symbol("fdatasync") fn libc_fdatasync(fd: int) int; + +export fn fdatasync(fd: int) (void | errno) = { + let res = libc_fdatasync(fd); + if (res == -1) { + return *__errno(): errno; + }; + return res; +}; + // setpriority @symbol("setpriority") fn libc_setpriority(