From patchwork Tue Jan 19 23:56:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 43238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D12B8B7CEA for ; Wed, 20 Jan 2010 11:05:18 +1100 (EST) Received: from localhost ([127.0.0.1]:47435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXO07-0007Ae-R2 for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2010 19:00:47 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXNw7-0005lK-Jo for qemu-devel@nongnu.org; Tue, 19 Jan 2010 18:56:39 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXNw2-0005i1-Sa for qemu-devel@nongnu.org; Tue, 19 Jan 2010 18:56:38 -0500 Received: from [199.232.76.173] (port=59369 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXNw2-0005ht-GO for qemu-devel@nongnu.org; Tue, 19 Jan 2010 18:56:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44706) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXNw1-0005ui-UB for qemu-devel@nongnu.org; Tue, 19 Jan 2010 18:56:34 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0JNuWUf031679 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 19 Jan 2010 18:56:33 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0JNuT3i027975; Tue, 19 Jan 2010 18:56:31 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 20 Jan 2010 00:56:08 +0100 Message-Id: <0db812948e253db268e1f1bebcc282197e4f880a.1263944807.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: kirill@shutemov.name Subject: [Qemu-devel] [PATCH 01/17] Introduce qemu_write_full() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kirill A. Shutemov A variant of write(2) which handles partial write. Signed-off-by: Kirill A. Shutemov Signed-off-by: Juan Quintela --- 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