Skip to content

Commit 6555ab4

Browse files
authored
unistd: fdatasync support for apple. (#2380)
is not present in system headers, however the syscall is actually implemented.
1 parent 15dcd6b commit 6555ab4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

changelog/2380.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add fdatasync support for Apple targets.

src/unistd.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,7 @@ pub fn fsync(fd: RawFd) -> Result<()> {
14111411
linux_android,
14121412
solarish,
14131413
netbsdlike,
1414+
apple_targets,
14141415
target_os = "freebsd",
14151416
target_os = "emscripten",
14161417
target_os = "fuchsia",
@@ -1419,7 +1420,18 @@ pub fn fsync(fd: RawFd) -> Result<()> {
14191420
))]
14201421
#[inline]
14211422
pub fn fdatasync(fd: RawFd) -> Result<()> {
1422-
let res = unsafe { libc::fdatasync(fd) };
1423+
cfg_if! {
1424+
// apple libc supports fdatasync too, albeit not being present in its headers
1425+
// [fdatasync](https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/vfs/vfs_syscalls.c#L7728)
1426+
if #[cfg(apple_targets)] {
1427+
extern "C" {
1428+
fn fdatasync(fd: libc::c_int) -> libc::c_int;
1429+
}
1430+
} else {
1431+
use libc::fdatasync as fdatasync;
1432+
}
1433+
}
1434+
let res = unsafe { fdatasync(fd) };
14231435

14241436
Errno::result(res).map(drop)
14251437
}

0 commit comments

Comments
 (0)