qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 01/15] Introduce qemu_write_full()
@ 2010-01-02  3:45 Kirill A. Shutemov
  2010-01-02  3:45 ` [Qemu-devel] [PATCH 02/15] posix-aio-compat.c: fix warning with _FORTIFY_SOURCE Kirill A. Shutemov
  2010-01-02 10:34 ` [Qemu-devel] Re: [PATCH 01/15] Introduce qemu_write_full() Paolo Bonzini
  0 siblings, 2 replies; 18+ messages in thread
From: Kirill A. Shutemov @ 2010-01-02  3:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kirill A. Shutemov

A variant of write(2) which handles partial write.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
 osdep.c       |   27 +++++++++++++++++++++++++++
 qemu-common.h |    2 ++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/osdep.c b/osdep.c
index e4836e7..8ae48fe 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.
+ */
+size_t qemu_write_full(int fd, const void *buf, size_t count)
+{
+    ssize_t ret;
+    size_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 8630f8c..7231348 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -160,6 +160,8 @@ void qemu_mutex_lock_iothread(void);
 void qemu_mutex_unlock_iothread(void);
 
 int qemu_open(const char *name, int flags, ...);
+size_t qemu_write_full(int fd, const void *buf, size_t count)
+    __attribute__ ((warn_unused_result));
 void qemu_set_cloexec(int fd);
 
 #ifndef _WIN32
-- 
1.6.5.7

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2010-01-05 16:39 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-02  3:45 [Qemu-devel] [PATCH 01/15] Introduce qemu_write_full() Kirill A. Shutemov
2010-01-02  3:45 ` [Qemu-devel] [PATCH 02/15] posix-aio-compat.c: fix warning with _FORTIFY_SOURCE Kirill A. Shutemov
2010-01-02  3:45   ` [Qemu-devel] [PATCH 03/15] block/cow.c: fix warnings " Kirill A. Shutemov
2010-01-02  3:45     ` [Qemu-devel] [PATCH 04/15] block/qcow.c: " Kirill A. Shutemov
2010-01-02  3:45       ` [Qemu-devel] [PATCH 05/15] block/vmdk.o: " Kirill A. Shutemov
2010-01-02  3:45         ` [Qemu-devel] [PATCH 06/15] block/vvfat.c: " Kirill A. Shutemov
2010-01-02  3:45           ` [Qemu-devel] [PATCH 07/15] block/qcow2.c: " Kirill A. Shutemov
2010-01-02  3:45             ` [Qemu-devel] [PATCH 08/15] net/slirp.c: fix warning " Kirill A. Shutemov
2010-01-02  3:45               ` [Qemu-devel] [PATCH 09/15] usb-linux.c: " Kirill A. Shutemov
2010-01-02  3:45                 ` [Qemu-devel] [PATCH 10/15] vl.c: " Kirill A. Shutemov
2010-01-02  3:45                   ` [Qemu-devel] [PATCH 11/15] monitor.c: fix warnings " Kirill A. Shutemov
2010-01-02  3:45                     ` [Qemu-devel] [PATCH 12/15] linux-user/mmap.c: " Kirill A. Shutemov
2010-01-02  3:45                       ` [Qemu-devel] [PATCH 13/15] Enable _FORTIFY_SOURCE=2 Kirill A. Shutemov
2010-01-02  3:45                         ` [Qemu-devel] [PATCH 14/15] Add -fstack-protector-all to CFLAGS Kirill A. Shutemov
2010-01-02  3:45                           ` [Qemu-devel] [PATCH 15/15] linux-user: fix return value of mmap_frag() Kirill A. Shutemov
     [not found]                 ` <m3zl4svci4.fsf@neno.neno>
2010-01-05 16:07                   ` [Qemu-devel] Re: [PATCH 09/15] usb-linux.c: fix warning with _FORTIFY_SOURCE Kirill A. Shutemov
2010-01-05 16:36                     ` Michael S. Tsirkin
2010-01-02 10:34 ` [Qemu-devel] Re: [PATCH 01/15] Introduce qemu_write_full() Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).