From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOTAm-0008IE-HG for qemu-devel@nongnu.org; Wed, 17 Oct 2012 08:56:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOTAf-0005el-QF for qemu-devel@nongnu.org; Wed, 17 Oct 2012 08:56:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19864) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOTAf-0005eb-HB for qemu-devel@nongnu.org; Wed, 17 Oct 2012 08:56:25 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9HCuOV3012502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 17 Oct 2012 08:56:24 -0400 From: Markus Armbruster References: <1349275025-5093-1-git-send-email-pbonzini@redhat.com> <1349275025-5093-2-git-send-email-pbonzini@redhat.com> Date: Wed, 17 Oct 2012 14:56:23 +0200 In-Reply-To: <1349275025-5093-2-git-send-email-pbonzini@redhat.com> (Paolo Bonzini's message of "Wed, 3 Oct 2012 16:36:48 +0200") Message-ID: <8762698dfs.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 01/18] error: add error_set_errno and error_setg_errno List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, lcapitulino@redhat.com Paolo Bonzini writes: > These functions help maintaining homogeneous formatting of error > messages that include strerror values. > > Signed-off-by: Paolo Bonzini > --- > error.c | 28 ++++++++++++++++++++++++++++ > error.h | 9 +++++++++ > 2 file modificati, 37 inserzioni(+) > > diff --git a/error.c b/error.c > index 1f05fc4..128d88c 100644 > --- a/error.c > +++ b/error.c > @@ -43,6 +43,34 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) > *errp = err; > } > > +void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, > + const char *fmt, ...) > +{ > + Error *err; > + char *msg1; > + va_list ap; > + > + if (errp == NULL) { > + return; > + } > + assert(*errp == NULL); > + > + err = g_malloc0(sizeof(*err)); > + > + va_start(ap, fmt); > + msg1 = g_strdup_vprintf(fmt, ap); > + if (os_errno != 0) { > + err->msg = g_strdup_printf("%s: %s", msg1, strerror(os_errno)); > + g_free(msg1); > + } else { > + err->msg = msg1; > + } > + va_end(ap); > + err->err_class = err_class; > + > + *errp = err; > +} > + Duplicates error_set() code without need. How about: void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, const char *fmt, ...) { char *msg; va_start(ap, fmt); msg = g_strdup_printf(fmt, ap); va_end(ap); if (os_errno) { error_set(errp, err_class, "%s: %s", msg, strerror(os_errno)); } else { error_set(errp, err_class, "%s", msg); } g_free(msg); } Sketch, not even compile-tested. Or the other way round, implement error_set() in terms of the more general error_set_errno(): void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) { error_set(errp, err_class, 0, fmt, ...); } Except that's not C; real code needs verror_set_errno(). As usual, every variadic function sooner or later needs a buddy that takes a va_list instead. > Error *error_copy(const Error *err) > { > Error *err_new; [...]