summaryrefslogtreecommitdiffstats
path: root/src/evalfunc.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-11-16 23:04:15 +0100
committerBram Moolenaar <Bram@vim.org>2017-11-16 23:04:15 +0100
commit7567d0b115e332f61a9f390aaccdf7825b891227 (patch)
treee4ab87bf66391ca7243d819c768dc907cdd411da /src/evalfunc.c
parentd0480097177369a6ed91d47aba189ae647afcd68 (diff)
patch 8.0.1305: writefile() never calls fsync()v8.0.1305
Problem: Writefile() never calls fsync(). Solution: Follow the 'fsync' option with override to enable or disable.
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 1991aa7c62..25b28bb3a2 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -13348,6 +13348,9 @@ f_writefile(typval_T *argvars, typval_T *rettv)
{
int binary = FALSE;
int append = FALSE;
+#ifdef HAVE_FSYNC
+ int do_fsync = p_fs;
+#endif
char_u *fname;
FILE *fd;
int ret = 0;
@@ -13380,6 +13383,12 @@ f_writefile(typval_T *argvars, typval_T *rettv)
binary = TRUE;
if (vim_strchr(arg2, 'a') != NULL)
append = TRUE;
+#ifdef HAVE_FSYNC
+ if (vim_strchr(arg2, 's') != NULL)
+ do_fsync = TRUE;
+ else if (vim_strchr(arg2, 'S') != NULL)
+ do_fsync = FALSE;
+#endif
}
fname = get_tv_string_chk(&argvars[1]);
@@ -13398,6 +13407,10 @@ f_writefile(typval_T *argvars, typval_T *rettv)
{
if (write_list(fd, list, binary) == FAIL)
ret = -1;
+#ifdef HAVE_FSYNC
+ else if (do_fsync && fsync(fileno(fd)) != 0)
+ EMSG(_(e_fsync));
+#endif
fclose(fd);
}