From patchwork Wed May 30 14:14:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 161969 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AF5AEB7069 for ; Thu, 31 May 2012 00:15:24 +1000 (EST) Received: from localhost ([::1]:48713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZjgH-00073M-8h for incoming@patchwork.ozlabs.org; Wed, 30 May 2012 10:15:21 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZjg3-0006a4-Gw for qemu-devel@nongnu.org; Wed, 30 May 2012 10:15:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SZjfx-0007Uc-9G for qemu-devel@nongnu.org; Wed, 30 May 2012 10:15:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17031) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZjfx-0007Tq-0y for qemu-devel@nongnu.org; Wed, 30 May 2012 10:15:01 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4UEEul2004656 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 30 May 2012 10:14:56 -0400 Received: from localhost (ovpn-116-69.ams2.redhat.com [10.36.116.69]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q4UEEsCk013920; Wed, 30 May 2012 10:14:55 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 30 May 2012 11:14:51 -0300 Message-Id: <1338387301-10074-5-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1338387301-10074-1-git-send-email-lcapitulino@redhat.com> References: <1338387301-10074-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, alevy@redhat.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 04/14] cutils: introduce qemu_fprintf_err() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org A fprintf() wrapper that takes an Error argument. Signed-off-by: Luiz Capitulino --- cutils.c | 31 +++++++++++++++++++++++++++++++ qemu-common.h | 1 + 2 files changed, 32 insertions(+) diff --git a/cutils.c b/cutils.c index 85dbb06..7bbd1b7 100644 --- a/cutils.c +++ b/cutils.c @@ -594,3 +594,34 @@ FILE *qemu_fopen_err(const char *path, const char *mode, Error **errp) return fp; } + +static void set_write_err(Error **errp, int err_nr) +{ + switch (err_nr) { + case ENOSPC: + error_set(errp, QERR_NO_SPACE); + return; + case EFBIG: + error_set(errp, QERR_FILE_TOO_BIG); + return; + default: + error_set(errp, QERR_IO_ERROR); + return; + } +} + +int qemu_fprintf_err(Error **errp, FILE *stream, const char *format, ...) +{ + va_list ap; + int ret; + + va_start(ap, format); + ret = vfprintf(stream, format, ap); + va_end(ap); + + if (ret < 0) { + set_write_err(errp, errno); + } + + return ret; +} diff --git a/qemu-common.h b/qemu-common.h index 2cab2a8..58c5197 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -210,6 +210,7 @@ int qemu_recvv(int sockfd, struct iovec *iov, int len, int iov_offset); int qemu_sendv(int sockfd, struct iovec *iov, int len, int iov_offset); FILE *qemu_fopen_err(const char *path, const char *mode, Error **errp); +int qemu_fprintf_err(Error **errp, FILE *stream, const char *format, ...); /* Error handling. */