Skip to content

Instantly share code, notes, and snippets.

@mattn
Created November 25, 2017 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/77b1478b48ce7c84ac8694d2e623d431 to your computer and use it in GitHub Desktop.
Save mattn/77b1478b48ce7c84ac8694d2e623d431 to your computer and use it in GitHub Desktop.
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 8d288e0..ad017af 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -13449,8 +13449,14 @@ 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));
+ else
+ {
+ int fno = fileno(fd);
+ struct stat st;
+ if (do_fsync && fstat(fno, &st) == 0 && S_ISREG(fno)
+ && fsync(fno) != 0)
+ EMSG(_(e_fsync));
+ }
#endif
fclose(fd);
}
diff --git a/src/testdir/test_writefile.vim b/src/testdir/test_writefile.vim
index 9703323b..a5ec487 100644
--- a/src/testdir/test_writefile.vim
+++ b/src/testdir/test_writefile.vim
@@ -100,3 +100,10 @@ func Test_writefile_sync_arg()
call writefile(['two'], 'Xtest', 'S')
call delete('Xtest')
endfunc
+
+func Test_writefile_sync_dev_stdout()
+ if has('win32')
+ return
+ endif
+ call writefile(['one'], '/dev/stdout')
+endfunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment