Patchwork [06/14] cutils: introduce qemu_fwrite_err()

login
register
mail settings
Submitter Luiz Capitulino
Date May 30, 2012, 2:14 p.m.
Message ID <1338387301-10074-7-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/161990/
State New
Headers show

Comments

Luiz Capitulino - May 30, 2012, 2:14 p.m.
A fwrite() wrapper that takes an Error argument.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 cutils.c      | 15 +++++++++++++++
 qemu-common.h |  2 ++
 2 files changed, 17 insertions(+)

Patch

diff --git a/cutils.c b/cutils.c
index c44ead9..646e08a 100644
--- a/cutils.c
+++ b/cutils.c
@@ -637,3 +637,18 @@  int qemu_fputc_err(int c, FILE *stream, Error **errp)
 
     return ret;
 }
+
+size_t qemu_fwrite_err(const void *ptr, size_t size, size_t nmemb,
+                       FILE *stream, Error **errp)
+{
+    size_t ret;
+
+    clearerr(stream);
+    ret = fwrite(ptr, size, nmemb, stream);
+
+    if (ferror(stream)) {
+        set_write_err(errp, errno);
+    }
+
+    return ret;
+}
diff --git a/qemu-common.h b/qemu-common.h
index 895bc2b..39377ff 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -212,6 +212,8 @@  int qemu_sendv(int sockfd, struct iovec *iov, int len, int iov_offset);
 FILE *qemu_fopen_err(const char *path, const char *mode, Error **errp);
 int qemu_fprintf_err(Error **errp, FILE *stream, const char *format, ...);
 int qemu_fputc_err(int c, FILE *stream, Error **errp);
+size_t qemu_fwrite_err(const void *ptr, size_t size, size_t nmemb,
+                       FILE *stream, Error **errp);
 
 /* Error handling.  */