git » libjio » commit aa47917

Support platforms lacking fdatasync()

author Alberto Bertogli
2009-06-26 05:40:12 UTC
committer Alberto Bertogli
2009-06-26 06:01:15 UTC
parent 7b241f1d51c5c1777edb088a54dd783f550af624

Support platforms lacking fdatasync()

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

libjio/compat.c +10 -0
libjio/compat.h +10 -0

diff --git a/libjio/compat.c b/libjio/compat.c
index 394ff39..6ca8cd3 100644
--- a/libjio/compat.c
+++ b/libjio/compat.c
@@ -86,4 +86,14 @@ int clock_gettime(int clk_id, struct timespec *tp)
 
 #endif /* defined LACK_CLOCK_GETTIME */
 
+#ifdef LACK_FDATASYNC
+#warning "Assuming no fdatasync(), falling back to fsync()"
+
+#include <unistd.h>		/* fsync() */
+
+int fdatasync(int fd)
+{
+	return fsync(fd);
+}
+#endif /* defined LACK_FDATASYNC */
 
diff --git a/libjio/compat.h b/libjio/compat.h
index 08b9c08..3cd7326 100644
--- a/libjio/compat.h
+++ b/libjio/compat.h
@@ -26,6 +26,16 @@ int sync_range_wait(int fd, off_t offset, size_t nbytes);
 #define posix_fadvise(fd, offset, len, advise)
 #endif
 
+
+/* fdatasync() is super standard, but some BSDs (FreeBSD, DragonflyBSD at
+ * least) do not have it. Since there is no reliable way to test for it, we
+ * have to resort to OS detection. */
+#if ! ( (defined __linux__) || (defined (__SVR4) && defined (__sun)) )
+#define LACK_FDATASYNC 1
+int fdatasync(int fd);
+#endif
+
+
 /* Some platforms do not have clock_gettime() so we define an alternative for
  * them, in compat.c. We should check for _POSIX_TIMERS, but some platforms do
  * not have it yet they do have clock_gettime() (DragonflyBSD), so we just