[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V2 03/10] error: add function error_set_check()
From: |
Wenchao Xia |
Subject: |
[Qemu-devel] [PATCH V2 03/10] error: add function error_set_check() |
Date: |
Mon, 7 Jan 2013 15:28:01 +0800 |
This function will return instead of abort when *errp is not NULL.
Also macro error_setg_check is added.
Signed-off-by: Wenchao Xia <address@hidden>
---
error.c | 19 +++++++++++++++++++
include/qapi/error.h | 5 +++++
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/error.c b/error.c
index 519f6b6..e4ec67c 100644
--- a/error.c
+++ b/error.c
@@ -43,6 +43,25 @@ void error_set(Error **errp, ErrorClass err_class, const
char *fmt, ...)
*errp = err;
}
+void error_set_check(Error **errp, ErrorClass err_class, const char *fmt, ...)
+{
+ Error *err;
+ va_list ap;
+
+ if ((errp == NULL) || (*errp != NULL)) {
+ return;
+ }
+
+ err = g_malloc0(sizeof(*err));
+
+ va_start(ap, fmt);
+ err->msg = g_strdup_vprintf(fmt, ap);
+ va_end(ap);
+ err->err_class = err_class;
+
+ *errp = err;
+}
+
void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
const char *fmt, ...)
{
diff --git a/include/qapi/error.h b/include/qapi/error.h
index 5cd2f0c..04b87a9 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -29,6 +29,9 @@ typedef struct Error Error;
*/
void error_set(Error **err, ErrorClass err_class, const char *fmt, ...)
GCC_FMT_ATTR(3, 4);
+void error_set_check(Error **errp, ErrorClass err_class, const char *fmt, ...)
+GCC_FMT_ATTR(3, 4);
+
/**
* Set an indirect pointer to an error given a ErrorClass value and a
* printf-style human message, followed by a strerror() string if
@@ -41,6 +44,8 @@ void error_set_errno(Error **err, int os_error, ErrorClass
err_class, const char
*/
#define error_setg(err, fmt, ...) \
error_set(err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)
+#define error_setg_check(err, fmt, ...) \
+ error_set_check(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__)
--
1.7.1
- [Qemu-devel] [PATCH V2 00/10] snapshot: take block snapshots in unified way, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 02/10] block: add function deappend(), Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 03/10] error: add function error_set_check(),
Wenchao Xia <=
- [Qemu-devel] [PATCH V2 01/10] block: export function bdrv_find_snapshot(), Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 04/10] oslib-win32: add lock for time functions, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 04/10] oslib-win32: add lock for time functions, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 06/10] snapshot: implemention of internal common API to take snapshots, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 09/10] snapshot: qmp add blockdev-snapshot-internal-sync interface, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 05/10] snapshot: design of internal common API to take snapshots, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 10/10] snapshot: hmp add internal snapshot support for block device, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 07/10] snapshot: qmp use new internal API for external snapshot transaction, Wenchao Xia, 2013/01/07