From patchwork Mon Jan 7 07:28:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [V2,03/10] error: add function error_set_check() Date: Sun, 06 Jan 2013 21:28:01 -0000 From: Wayne Xia X-Patchwork-Id: 209868 Message-Id: <1357543689-11415-4-git-send-email-xiawenc@linux.vnet.ibm.com> To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, Wenchao Xia , lcapitulino@redhat.com, pbonzini@redhat.com, dietmar@proxmox.com This function will return instead of abort when *errp is not NULL. Also macro error_setg_check is added. Signed-off-by: Wenchao Xia --- 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__)