aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-04-03 03:54:34 +0200
committerGitHub <noreply@github.com>2017-04-03 03:54:34 +0200
commit6afa7d66cd6343c7c0114e6b3e08c592e169df43 (patch)
treeb9bf75bedadd6a00347cd9f4396d159562fb7675 /src/nvim/os
parentddfa0359c638a4fd5eba5c339dc3e18e2b8aca35 (diff)
parentae7d8d8ffb86eefa45d8f59834eb0f088e93535d (diff)
downloadrneovim-6afa7d66cd6343c7c0114e6b3e08c592e169df43.tar.gz
rneovim-6afa7d66cd6343c7c0114e6b3e08c592e169df43.tar.bz2
rneovim-6afa7d66cd6343c7c0114e6b3e08c592e169df43.zip
Merge #6427 from ZyX-I/writefile-allow-omitting-fsync
eval: Make writefile() able to disable fsync()
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/env.c7
-rw-r--r--src/nvim/os/fileio.c20
2 files changed, 16 insertions, 11 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index a10c835591..1a97adfa21 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -703,7 +703,8 @@ char *vim_getenv(const char *name)
/// @param dstlen Maximum length of the result
/// @param one If true, only replace one file name, including spaces and commas
/// in the file name
-void home_replace(buf_T *buf, char_u *src, char_u *dst, int dstlen, bool one)
+void home_replace(const buf_T *const buf, const char_u *src,
+ char_u *dst, size_t dstlen, bool one)
{
size_t dirlen = 0, envlen = 0;
size_t len;
@@ -717,7 +718,7 @@ void home_replace(buf_T *buf, char_u *src, char_u *dst, int dstlen, bool one)
* If the file is a help file, remove the path completely.
*/
if (buf != NULL && buf->b_help) {
- STRCPY(dst, path_tail(src));
+ xstrlcpy((char *)dst, (char *)path_tail(src), dstlen);
return;
}
@@ -809,7 +810,7 @@ char_u * home_replace_save(buf_T *buf, char_u *src) FUNC_ATTR_NONNULL_RET
len += STRLEN(src);
}
char_u *dst = xmalloc(len);
- home_replace(buf, src, dst, (int)len, true);
+ home_replace(buf, src, dst, len, true);
return dst;
}
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;
}