Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unistd: fdatasync support for apple. #2380

Merged
merged 1 commit into from
Apr 21, 2024
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