aboutsummaryrefslogtreecommitdiff
path: root/osdep.c
diff options
context:
space:
mode:
authorKirill A. Shutemov <kirill@shutemov.name>2010-01-20 00:56:08 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2010-01-26 14:59:19 -0600
commit7b5f699dbdf64cf9657e2955bccccc173d9b09fc (patch)
tree9f714a9eb0cc512bb871e18099140051ffe50607 /osdep.c
parent5d757b563d59142ca81e1073a8e8396750a0ad1a (diff)
Introduce qemu_write_full()
A variant of write(2) which handles partial write. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'osdep.c')
-rw-r--r--osdep.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/osdep.c b/osdep.c
index 1310684e3c..09fbc992e3 100644
--- a/osdep.c
+++ b/osdep.c
@@ -243,6 +243,33 @@ int qemu_open(const char *name, int flags, ...)
return ret;
}
+/*
+ * A variant of write(2) which handles partial write.
+ *
+ * Return the number of bytes transferred.
+ * Set errno if fewer than `count' bytes are written.
+ */
+ssize_t qemu_write_full(int fd, const void *buf, size_t count)
+{
+ ssize_t ret = 0;
+ ssize_t total = 0;
+
+ while (count) {
+ ret = write(fd, buf, count);
+ if (ret < 0) {
+ if (errno == EINTR)
+ continue;
+ break;
+ }
+
+ count -= ret;
+ buf += ret;
+ total += ret;
+ }
+
+ return total;
+}
+
#ifndef _WIN32
/*
* Creates a pipe with FD_CLOEXEC set on both file descriptors