aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-07-04 17:03:07 +0300
committerZyX <kp-pav@yandex.ru>2017-07-04 18:37:01 +0300
commit5ab9e9f617934fae8f85ceb6db398dbf1e93471d (patch)
tree98a9aa561834cf61459cec70c5e6e75b36d11ade /src
parent94bd0f9915b0515fde449e3ee003ecbff3ad1b42 (diff)
downloadrneovim-5ab9e9f617934fae8f85ceb6db398dbf1e93471d.tar.gz
rneovim-5ab9e9f617934fae8f85ceb6db398dbf1e93471d.tar.bz2
rneovim-5ab9e9f617934fae8f85ceb6db398dbf1e93471d.zip
os/fileio: Add msgpack_file_write function
Diffstat (limited to 'src')
-rw-r--r--src/nvim/os/fileio.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c
index 4309ac723c..d16746b7bf 100644
--- a/src/nvim/os/fileio.c
+++ b/src/nvim/os/fileio.c
@@ -26,6 +26,7 @@
#include "nvim/globals.h"
#include "nvim/rbuffer.h"
#include "nvim/macros.h"
+#include "nvim/message.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/fileio.c.generated.h"
@@ -345,3 +346,23 @@ ptrdiff_t file_skip(FileDescriptor *const fp, const size_t size)
return (ptrdiff_t)read_bytes;
}
+
+/// Msgpack callback for writing to a file
+///
+/// @param data File to write to.
+/// @param[in] buf Data to write.
+/// @param[in] len Length of the data to write.
+///
+/// @return 0 in case of success, -1 in case of error.
+int msgpack_file_write(void *data, const char *buf, size_t len)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
+{
+ 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 0;
+}