From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZt3B-0003zu-CF for qemu-devel@nongnu.org; Tue, 26 Jan 2010 16:34:17 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZt36-0003wC-BP for qemu-devel@nongnu.org; Tue, 26 Jan 2010 16:34:16 -0500 Received: from [199.232.76.173] (port=43012 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZt36-0003w3-6n for qemu-devel@nongnu.org; Tue, 26 Jan 2010 16:34:12 -0500 Received: from mail-iw0-f188.google.com ([209.85.223.188]:54690) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NZt36-0006C3-1X for qemu-devel@nongnu.org; Tue, 26 Jan 2010 16:34:12 -0500 Received: by iwn26 with SMTP id 26so5343845iwn.14 for ; Tue, 26 Jan 2010 13:34:10 -0800 (PST) Message-ID: <4B5F5FCF.80007@codemonkey.ws> Date: Tue, 26 Jan 2010 15:34:07 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 01/17] Introduce qemu_write_full() References: <0db812948e253db268e1f1bebcc282197e4f880a.1263944807.git.quintela@redhat.com> In-Reply-To: <0db812948e253db268e1f1bebcc282197e4f880a.1263944807.git.quintela@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Juan Quintela Cc: kirill@shutemov.name, qemu-devel@nongnu.org On 01/19/2010 05:56 PM, Juan Quintela wrote: > From: Kirill A. Shutemov > > A variant of write(2) which handles partial write. > > Signed-off-by: Kirill A. Shutemov > Signed-off-by: Juan Quintela > 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 >