aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/fileio.c
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-04-02 22:11:35 +0300
committerZyX <kp-pav@yandex.ru>2017-04-02 22:11:35 +0300
commitb10880dadcbd3b3ad368621f95a0f4be7e30dc0d (patch)
treed2546048e984a65178fabd9f5d43fcafec1b9320 /src/nvim/os/fileio.c
parentddfa0359c638a4fd5eba5c339dc3e18e2b8aca35 (diff)
downloadrneovim-b10880dadcbd3b3ad368621f95a0f4be7e30dc0d.tar.gz
rneovim-b10880dadcbd3b3ad368621f95a0f4be7e30dc0d.tar.bz2
rneovim-b10880dadcbd3b3ad368621f95a0f4be7e30dc0d.zip
eval: Make writefile() able to disable fsync()
Diffstat (limited to 'src/nvim/os/fileio.c')
-rw-r--r--src/nvim/os/fileio.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c
index 3c928363cc..4b7b53fc7f 100644
--- a/src/nvim/os/fileio.c
+++ b/src/nvim/os/fileio.c
@@ -113,27 +113,31 @@ FileDescriptor *file_open_new(int *const error, const char *const fname,
/// Close file and free its buffer
///
/// @param[in,out] fp File to close.
+/// @param[in] do_fsync If true, use fsync() to write changes to disk.
///
/// @return 0 or error code.
-int file_close(FileDescriptor *const fp) FUNC_ATTR_NONNULL_ALL
+int file_close(FileDescriptor *const fp, const bool do_fsync)
+ FUNC_ATTR_NONNULL_ALL
{
- const int error = file_fsync(fp);
- const int error2 = os_close(fp->fd);
+ const int flush_error = (do_fsync ? file_fsync(fp) : file_flush(fp));
+ const int close_error = os_close(fp->fd);
rbuffer_free(fp->rv);
- if (error2 != 0) {
- return error2;
+ if (close_error != 0) {
+ return close_error;
}
- return error;
+ return flush_error;
}
/// Close and free file obtained using file_open_new()
///
/// @param[in,out] fp File to close.
+/// @param[in] do_fsync If true, use fsync() to write changes to disk.
///
/// @return 0 or error code.
-int file_free(FileDescriptor *const fp) FUNC_ATTR_NONNULL_ALL
+int file_free(FileDescriptor *const fp, const bool do_fsync)
+ FUNC_ATTR_NONNULL_ALL
{
- const int ret = file_close(fp);
+ const int ret = file_close(fp, do_fsync);
xfree(fp);
return ret;
}