Not sure if anyone finds this useful. Let me know.

PS. Windows bit is a complete guess. OS2 bit I had no idea about, so
just stubs.

-- 
Bojan
Index: include/apr_file_io.h
===================================================================
--- include/apr_file_io.h	(revision 783964)
+++ include/apr_file_io.h	(working copy)
@@ -565,6 +565,18 @@
 APR_DECLARE(apr_status_t) apr_file_flush(apr_file_t *thefile);
 
 /**
+ * Transfer all file modified data and metadata to disk.
+ * @param thefile The file descriptor to sync
+ */
+APR_DECLARE(apr_status_t) apr_file_sync(apr_file_t *thefile);
+
+/**
+ * Transfer all file modified data to disk.
+ * @param thefile The file descriptor to sync
+ */
+APR_DECLARE(apr_status_t) apr_file_datasync(apr_file_t *thefile);
+
+/**
  * Duplicate the specified file descriptor.
  * @param new_file The structure to duplicate into. 
  * @param old_file The file to duplicate.
Index: file_io/win32/readwrite.c
===================================================================
--- file_io/win32/readwrite.c	(revision 783964)
+++ file_io/win32/readwrite.c	(working copy)
@@ -516,6 +516,25 @@
     return APR_SUCCESS; 
 }
 
+APR_DECLARE(apr_status_t) apr_file_sync(apr_file_t *thefile){
+    apr_status_t rv;
+
+    rv = apr_file_flush(thefile);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    if (!FlushFileBuffers(thefile->filehand)){
+        rv = apr_get_os_error();
+    }
+
+    return rv;
+}
+
+APR_DECLARE(apr_status_t) apr_file_datasync(apr_file_t *thefile){
+    return apr_file_sync(thefile);
+}
+
 struct apr_file_printf_data {
     apr_vformatter_buff_t vbuff;
     apr_file_t *fptr;
Index: file_io/os2/readwrite.c
===================================================================
--- file_io/os2/readwrite.c	(revision 783964)
+++ file_io/os2/readwrite.c	(working copy)
@@ -304,7 +304,16 @@
     }
 }
 
+APR_DECLARE(apr_status_t) apr_file_sync(apr_file_t *thefile)
+{
+    return APR_SUCCESS;
+}
 
+APR_DECLARE(apr_status_t) apr_file_datasync(apr_file_t *thefile)
+{
+    return APR_SUCCESS;
+}
+
 APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t *thefile)
 {
     apr_size_t readlen;
Index: file_io/unix/readwrite.c
===================================================================
--- file_io/unix/readwrite.c	(revision 783964)
+++ file_io/unix/readwrite.c	(working copy)
@@ -342,6 +342,54 @@
     return rv;
 }
 
+APR_DECLARE(apr_status_t) apr_file_sync(apr_file_t *thefile)
+{
+    apr_status_t rv = APR_SUCCESS;
+
+    file_lock(thefile);
+
+    if (thefile->buffered) {
+        rv = apr_file_flush_locked(thefile);
+
+        if (rv != APR_SUCCESS) {
+            file_unlock(thefile);
+            return rv;
+        }
+    }
+
+    if (fsync(thefile->filedes) != 0) {
+        rv = apr_get_os_error();
+    }
+
+    file_unlock(thefile);
+
+    return rv;
+}
+
+APR_DECLARE(apr_status_t) apr_file_datasync(apr_file_t *thefile)
+{
+    apr_status_t rv = APR_SUCCESS;
+
+    file_lock(thefile);
+
+    if (thefile->buffered) {
+        rv = apr_file_flush_locked(thefile);
+
+        if (rv != APR_SUCCESS) {
+            file_unlock(thefile);
+            return rv;
+        }
+    }
+
+    if (fdatasync(thefile->filedes) != 0) {
+        rv = apr_get_os_error();
+    }
+
+    file_unlock(thefile);
+
+    return rv;
+}
+
 APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t *thefile)
 {
     apr_status_t rv = APR_SUCCESS; /* get rid of gcc warning */

Reply via email to