From patchwork Wed Aug 7 15:40:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomoki Sekiyama X-Patchwork-Id: 265544 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 282922C0098 for ; Thu, 8 Aug 2013 01:45:10 +1000 (EST) Received: from localhost ([::1]:54941 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V75vA-0004tt-DF for incoming@patchwork.ozlabs.org; Wed, 07 Aug 2013 11:45:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V75qc-0006fR-C0 for qemu-devel@nongnu.org; Wed, 07 Aug 2013 11:40:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V75qW-00058u-39 for qemu-devel@nongnu.org; Wed, 07 Aug 2013 11:40:26 -0400 Received: from usindpps03.hds.com ([207.126.252.16]:43448) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V75qV-00058k-UJ for qemu-devel@nongnu.org; Wed, 07 Aug 2013 11:40:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hds.com; h=subject : to : from : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=mail1; bh=pN79E5G6Hd+qNq5QmDKag+3QFnEZkqKNDkKPw+nJpbg=; b=c7PrD58qArgKPBiaaRg9cyK9ZXCTSMg62Amlp4mBrTRJC0Oxk/xTimcslpoHphPrhaN1 GAbD9C4Ew6kDqlsFsXJMhPSSIlWcstF/FwGsKx9ZVn0wggok3R0uob483z6aWX+sUiP0 6u7bH1BmYKwdDhZehicTfjXGM+W9L9glipu6Xuad9ZiC51JHcF8m/7ZALol9eTTiAvME v2R34q7OXyDf0NqulWm0tJo2Jetb78qCFM3siuMDzQ5w7urlFbE+BMXm+r/tVm4Usp/1 k+54NunivS/6ciX7Sa+CAa7fP1j8L8XbMQx9w6v3GRQLE1EXrBhaeRXa7B0SGXGccFc+ HQ== Received: from usindmail02.hds.com (usindmail02 [207.126.252.21]) by usindpps03.hds.com (8.14.5/8.14.5) with ESMTP id r77FeDwn002334; Wed, 7 Aug 2013 11:40:13 -0400 Received: from hds.com (usindnetf5d-vlan47float.corp.hds.com [10.74.73.11]) by usindmail02.hds.com (8.14.1/8.14.1) with ESMTP id r77FeB7K027645; Wed, 7 Aug 2013 11:40:12 -0400 (EDT) To: qemu-devel@nongnu.org From: Tomoki Sekiyama Date: Wed, 07 Aug 2013 11:40:11 -0400 Message-ID: <20130807154011.16124.68924.stgit@hds.com> In-Reply-To: <20130807153925.16124.93648.stgit@hds.com> References: <20130807153925.16124.93648.stgit@hds.com> User-Agent: StGit/0.16 MIME-Version: 1.0 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 mx ip4:207.126.244.0/26 ip4:207.126.252.0/25 include:mktomail.com include:cloud.hds.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.10.8794, 1.0.431, 0.0.0000 definitions=2013-08-07_01:2013-08-06, 2013-08-07, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=outbound_policy score=0 kscore.is_bulkscore=0 kscore.compositescore=0 circleOfTrustscore=18.8327455224771 compositescore=0.0264147887545331 urlsuspect_oldscore=0.997914092941733 suspectscore=3 recipient_domain_to_sender_totalscore=14 phishscore=0 bulkscore=0 kscore.is_spamscore=0 recipient_to_sender_totalscore=2 recipient_domain_to_sender_domain_totalscore=87401 rbsscore=0.0264147887545331 spamscore=0 recipient_to_sender_domain_totalscore=4 urlsuspectscore=0.9 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1305240000 definitions=main-1308070122 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 207.126.252.16 Cc: libaiqing@huawei.com, ghammer@redhat.com, stefanha@gmail.com, Michael Roth , lcapitulino@redhat.com, vrozenfe@redhat.com, pbonzini@redhat.com, seiji.aguchi@hds.com, lersek@redhat.com, areis@redhat.com Subject: [Qemu-devel] [PATCH v10 06/10] error: Add error_set_win32 and error_setg_win32 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 These functions help maintaining homogeneous formatting of error messages with Windows error code and description (generated by g_win32_error_message()). Signed-off-by: Tomoki Sekiyama Reviewed-by: Michael Roth --- include/qapi/error.h | 13 +++++++++++++ util/error.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/qapi/error.h b/include/qapi/error.h index ffd1cea..7d4c696 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -36,6 +36,15 @@ void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ */ void error_set_errno(Error **err, int os_error, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(4, 5); +#ifdef _WIN32 +/** + * Set an indirect pointer to an error given a ErrorClass value and a + * printf-style human message, followed by a g_win32_error_message() string if + * @win32_err is not zero. + */ +void error_set_win32(Error **err, int win32_err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(4, 5); +#endif + /** * Same as error_set(), but sets a generic error */ @@ -43,6 +52,10 @@ void error_set_errno(Error **err, int os_error, ErrorClass err_class, const char error_set(err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__) #define error_setg_errno(err, os_error, fmt, ...) \ error_set_errno(err, os_error, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__) +#ifdef _WIN32 +#define error_setg_win32(err, win32_err, fmt, ...) \ + error_set_win32(err, win32_err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__) +#endif /** * Helper for open() errors diff --git a/util/error.c b/util/error.c index 53b0435..ec0faa6 100644 --- a/util/error.c +++ b/util/error.c @@ -76,6 +76,41 @@ void error_setg_file_open(Error **errp, int os_errno, const char *filename) error_setg_errno(errp, os_errno, "Could not open '%s'", filename); } +#ifdef _WIN32 + +void error_set_win32(Error **errp, int win32_err, 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 (win32_err != 0) { + char *msg2 = g_win32_error_message(win32_err); + err->msg = g_strdup_printf("%s: %s (error: %x)", msg1, msg2, + (unsigned)win32_err); + g_free(msg2); + g_free(msg1); + } else { + err->msg = msg1; + } + va_end(ap); + err->err_class = err_class; + + *errp = err; +} + +#endif + Error *error_copy(const Error *err) { Error *err_new;