about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThomas de Zeeuw <thomasdezeeuw@gmail.com>2020-10-13 15:57:31 +0200
committerThomas de Zeeuw <thomasdezeeuw@gmail.com>2020-10-13 15:57:31 +0200
commit8c0c7ec4ec6c4f305c229d74f74f08f86a59fc69 (patch)
treeab9d6c44193f41d65ba681191143a8d7eab0fc2a
parent782013564efc06ef02614ba35a4e67dee4fcb8e7 (diff)
downloadrust-8c0c7ec4ec6c4f305c229d74f74f08f86a59fc69.tar.gz
rust-8c0c7ec4ec6c4f305c229d74f74f08f86a59fc69.zip
Use fdatasync for File::sync_data on more OSes
Add support for the following OSes:
 * Android
 * FreeBSD: https://www.freebsd.org/cgi/man.cgi?query=fdatasync&sektion=2
 * OpenBSD: https://man.openbsd.org/OpenBSD-5.8/fsync.2
 * NetBSD: https://man.netbsd.org/fdatasync.2
 * illumos: https://illumos.org/man/3c/fdatasync
-rw-r--r--library/std/src/sys/unix/fs.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs
index 566ac0920dc..576cc24cc0f 100644
--- a/library/std/src/sys/unix/fs.rs
+++ b/library/std/src/sys/unix/fs.rs
@@ -752,11 +752,25 @@ impl File {
         unsafe fn os_datasync(fd: c_int) -> c_int {
             libc::fcntl(fd, libc::F_FULLFSYNC)
         }
-        #[cfg(target_os = "linux")]
+        #[cfg(any(
+            target_os = "freebsd",
+            target_os = "linux",
+            target_os = "android",
+            target_os = "netbsd",
+            target_os = "openbsd"
+        ))]
         unsafe fn os_datasync(fd: c_int) -> c_int {
             libc::fdatasync(fd)
         }
-        #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "linux")))]
+        #[cfg(not(any(
+            target_os = "android",
+            target_os = "freebsd",
+            target_os = "ios",
+            target_os = "linux",
+            target_os = "macos",
+            target_os = "netbsd",
+            target_os = "openbsd"
+        )))]
         unsafe fn os_datasync(fd: c_int) -> c_int {
             libc::fsync(fd)
         }