diff options
author | Kirill A. Shutemov <kirill@shutemov.name> | 2010-01-20 00:56:08 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2010-01-26 14:59:19 -0600 |
commit | d84a61783e03e6b0e47cd5303e24cfc65d10e63f (patch) | |
tree | 9f714a9eb0cc512bb871e18099140051ffe50607 | |
parent | a29ee24c9ab3b0988cfe9e3d77d6c750a7090859 (diff) | |
download | qemu-d84a61783e03e6b0e47cd5303e24cfc65d10e63f.tar.gz qemu-d84a61783e03e6b0e47cd5303e24cfc65d10e63f.tar.bz2 qemu-d84a61783e03e6b0e47cd5303e24cfc65d10e63f.zip |
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>
-rw-r--r-- | osdep.c | 27 | ||||
-rw-r--r-- | qemu-common.h | 1 |
2 files changed, 28 insertions, 0 deletions
@@ -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 diff --git a/qemu-common.h b/qemu-common.h index d96060adbf..a2731e1514 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -161,6 +161,7 @@ void qemu_mutex_lock_iothread(void); void qemu_mutex_unlock_iothread(void); int qemu_open(const char *name, int flags, ...); +ssize_t qemu_write_full(int fd, const void *buf, size_t count); void qemu_set_cloexec(int fd); #ifndef _WIN32 |