Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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