qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 01/17] Introduce qemu_write_full()


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH 01/17] Introduce qemu_write_full()
Date: Tue, 26 Jan 2010 15:34:07 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.5) Gecko/20091209 Fedora/3.0-4.fc12 Lightning/1.0pre Thunderbird/3.0

On 01/19/2010 05:56 PM, Juan Quintela wrote:
From: Kirill A. Shutemov<address@hidden>

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

Signed-off-by: Kirill A. Shutemov<address@hidden>
Signed-off-by: Juan Quintela<address@hidden>

Applied all.  Thanks.

Regards,

Anthony Liguori

---
  osdep.c       |   27 +++++++++++++++++++++++++++
  qemu-common.h |    1 +
  2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/osdep.c b/osdep.c
index 1310684..09fbc99 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
diff --git a/qemu-common.h b/qemu-common.h
index 8630f8c..a8144cb 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -160,6 +160,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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]