summaryrefslogtreecommitdiffstats
path: root/src/fileio.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-02-14 12:56:36 +0100
committerBram Moolenaar <Bram@vim.org>2019-02-14 12:56:36 +0100
commita787019518a540a7b4d0070f15467931b870ac89 (patch)
tree684243a253d30b00c171f25144798f80400ecc4b /src/fileio.c
parent5fd0f5052f9a312bb4cfe7b4176b1211d45127ee (diff)
patch 8.1.0915: fsync() may not work properly on Macv8.1.0915
Problem: fsync() may not work properly on Mac. Solution: Use fcntl() with F_FULLFSYNC. (suggested by Justin M. Keyes)
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/fileio.c b/src/fileio.c
index c7f3ad1768..f9e18d413a 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4661,7 +4661,7 @@ restore_backup:
* work (could be a pipe).
* If the 'fsync' option is FALSE, don't fsync(). Useful for laptops.
*/
- if (p_fs && fsync(fd) != 0 && !device)
+ if (p_fs && vim_fsync(fd) != 0 && !device)
{
errmsg = (char_u *)_(e_fsync);
end = 0;
@@ -5123,6 +5123,25 @@ nofail:
return retval;
}
+#if defined(HAVE_FSYNC) || defined(PROTO)
+/*
+ * Call fsync() with Mac-specific exception.
+ * Return fsync() result: zero for success.
+ */
+ int
+vim_fsync(int fd)
+{
+ int r;
+
+# ifdef MACOS_X
+ r = fcntl(fd, F_FULLFSYNC);
+ if (r != 0 && errno == ENOTTY)
+# endif
+ r = fsync(fd);
+ return r;
+}
+#endif
+
/*
* Set the name of the current buffer. Use when the buffer doesn't have a
* name and a ":r" or ":w" command with a file name is used.