]> git.lizzy.rs Git - rust.git/commitdiff
Use fdatasync for File::sync_data on more OSes
authorThomas de Zeeuw <thomasdezeeuw@gmail.com>
Tue, 13 Oct 2020 13:57:31 +0000 (15:57 +0200)
committerThomas de Zeeuw <thomasdezeeuw@gmail.com>
Tue, 13 Oct 2020 13:57:31 +0000 (15:57 +0200)
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

library/std/src/sys/unix/fs.rs

index 566ac0920dc8f5762842b3585c20fc1cb5fc6d06..576cc24cc0f641de210cdfd804df6bb93ed58070 100644 (file)
@@ -752,11 +752,25 @@ pub fn datasync(&self) -> io::Result<()> {
         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)
         }