Skip to content

Commit

Permalink
unistd: fdatasync support for apple.
Browse files Browse the repository at this point in the history
is not present in system headers, however the syscall is actually
implemented.
  • Loading branch information
devnexen committed Apr 21, 2024
1 parent 15dcd6b commit 2ee97f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/2380.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add fdatasync support for Apple targets.
14 changes: 13 additions & 1 deletion src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ pub fn fsync(fd: RawFd) -> Result<()> {
linux_android,
solarish,
netbsdlike,
apple_targets,
target_os = "freebsd",
target_os = "emscripten",
target_os = "fuchsia",
Expand All @@ -1419,7 +1420,18 @@ pub fn fsync(fd: RawFd) -> Result<()> {
))]
#[inline]
pub fn fdatasync(fd: RawFd) -> Result<()> {
let res = unsafe { libc::fdatasync(fd) };
cfg_if! {
// apple libc supports fdatasync too, albeit not being present in its headers
// [fdatasync](https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/vfs/vfs_syscalls.c#L7728)
if #[cfg(apple_targets)] {
extern "C" {
fn fdatasync(fd: libc::c_int) -> libc::c_int;
}
} else {
use libc::fdatasync as fdatasync;
}
}
let res = unsafe { fdatasync(fd) };

Errno::result(res).map(drop)
}
Expand Down

0 comments on commit 2ee97f2

Please sign in to comment.