From patchwork Fri Jan 3 03:08:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 306558 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C9A722C00A5 for ; Fri, 3 Jan 2014 22:12:03 +1100 (EST) Received: from localhost ([::1]:49215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vz2fZ-0007rP-IV for incoming@patchwork.ozlabs.org; Fri, 03 Jan 2014 06:12:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35210) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vz2en-0007fw-It for qemu-devel@nongnu.org; Fri, 03 Jan 2014 06:11:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vz2eZ-0003ej-2S for qemu-devel@nongnu.org; Fri, 03 Jan 2014 06:11:13 -0500 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:59326) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vz2eW-0003dw-RX for qemu-devel@nongnu.org; Fri, 03 Jan 2014 06:10:58 -0500 Received: from /spool/local by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 3 Jan 2014 16:40:49 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp04.in.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 3 Jan 2014 16:40:47 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 9B1F7E0024 for ; Fri, 3 Jan 2014 16:43:28 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s03BAd8m4718984 for ; Fri, 3 Jan 2014 16:40:39 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s03BAjHP014095 for ; Fri, 3 Jan 2014 16:40:46 +0530 Received: from RH64wenchao ([9.181.129.59]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s03BAedh013788; Fri, 3 Jan 2014 16:40:45 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Fri, 3 Jan 2014 11:08:47 +0800 Message-Id: <1388718532-18264-4-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1388718532-18264-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1388718532-18264-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14010311-5564-0000-0000-00000B633257 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.4 Cc: kwolf@redhat.com, jcody@redhat.com, Wenchao Xia , stefanha@redhat.com, mreitz@redhat.com Subject: [Qemu-devel] [PATCH V8 3/8] util: add error_append() 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 Signed-off-by: Wenchao Xia --- include/qapi/error.h | 6 ++++++ util/error.c | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-) diff --git a/include/qapi/error.h b/include/qapi/error.h index 7d4c696..bcfb724 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -30,6 +30,12 @@ typedef struct Error Error; void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4); /** + * Append message to err if err != NULL && *err != NULL. "\n" will be inserted + * after old message. + */ +void error_append(Error **err, const char *fmt, ...) GCC_FMT_ATTR(2, 3); + +/** * Set an indirect pointer to an error given a ErrorClass value and a * printf-style human message, followed by a strerror() string if * @os_error is not zero. diff --git a/util/error.c b/util/error.c index 3ee362a..64bbb2d 100644 --- a/util/error.c +++ b/util/error.c @@ -46,6 +46,27 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) errno = saved_errno; } +void error_append(Error **err, const char *fmt, ...) +{ + va_list ap; + gchar *msg, *msg_old; + + if (!err || !*err) { + return; + } + + va_start(ap, fmt); + msg = g_strdup_vprintf(fmt, ap); + va_end(ap); + + msg_old = (*err)->msg; + (*err)->msg = g_strdup_printf("%s\n%s", msg_old, msg); + + g_free(msg); + g_free(msg_old); + +} + void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, const char *fmt, ...) {