From 1befe3e51e2593f909a456c62702f9cfe9a0dc29 Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Sun, 21 Apr 2024 09:39:02 +0800 Subject: [PATCH] feat: sync APIs for more platforms --- changelog/2379.added.md | 1 + src/unistd.rs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelog/2379.added.md diff --git a/changelog/2379.added.md b/changelog/2379.added.md new file mode 100644 index 0000000000..325abdc8ff --- /dev/null +++ b/changelog/2379.added.md @@ -0,0 +1 @@ +Add `sync(2)` for `apple_targets/solarish/haiku/aix/hurd`, `syncfs(2)` for `hurd` and `fdatasync(2)` for `aix/hurd` diff --git a/src/unistd.rs b/src/unistd.rs index c73786a6f5..8330245143 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1377,7 +1377,7 @@ pub fn chroot(path: &P) -> Result<()> { /// Commit filesystem caches to disk /// /// See also [sync(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/sync.html) -#[cfg(any(freebsdlike, linux_android, netbsdlike))] +#[cfg(any(bsd, linux_android, solarish, target_os = "haiku", target_os = "aix", target_os = "hurd"))] pub fn sync() { unsafe { libc::sync() }; } @@ -1386,7 +1386,7 @@ pub fn sync() { /// descriptor `fd` to disk /// /// See also [syncfs(2)](https://man7.org/linux/man-pages/man2/sync.2.html) -#[cfg(linux_android)] +#[cfg(any(linux_android, target_os = "hurd"))] pub fn syncfs(fd: RawFd) -> Result<()> { let res = unsafe { libc::syncfs(fd) }; @@ -1414,6 +1414,8 @@ pub fn fsync(fd: RawFd) -> Result<()> { target_os = "freebsd", target_os = "emscripten", target_os = "fuchsia", + target_os = "aix", + target_os = "hurd", ))] #[inline] pub fn fdatasync(fd: RawFd) -> Result<()> {