diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/main.c | 5 | ||||
-rw-r--r-- | src/nvim/os/fileio.c | 15 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index f55f876608..7dcf00c26b 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -783,7 +783,10 @@ static void command_line_scan(mparm_T *parmp) msgpack_rpc_from_object(md, p); msgpack_packer_free(p); - file_close(&fp, false); + const int ff_ret = file_flush(&fp); + if (ff_ret < 0) { + msgpack_file_write_error(ff_ret); + } mch_exit(0); } else if (STRICMP(argv[0] + argv_idx, "headless") == 0) { parmp->headless = true; diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index 0ed0ae87e3..5d68473982 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -400,9 +400,18 @@ int msgpack_file_write(void *data, const char *buf, size_t len) assert(len < PTRDIFF_MAX); const ptrdiff_t written_bytes = file_write((FileDescriptor *)data, buf, len); if (written_bytes < 0) { - emsgf(_("E5420: Failed to write to file: %s"), - os_strerror((int)written_bytes)); - return -1; + return msgpack_file_write_error((int)written_bytes); } return 0; } + +/// Print error which occurs when failing to write msgpack data +/// +/// @param[in] error Error code of the error to print. +/// +/// @return -1 (error return for msgpack_packer callbacks). +int msgpack_file_write_error(const int error) +{ + emsgf(_("E5420: Failed to write to file: %s"), os_strerror(error)); + return -1; +} |