They mirror g_set_error[_literal] functionality but append the error reported by libvirt to the error message. --- libvirt-glib/libvirt-glib-error.c | 49 +++++++++++++++++++++++++++++++++++++ libvirt-glib/libvirt-glib-error.h | 11 ++++++++ libvirt-glib/libvirt-glib.sym | 2 + 3 files changed, 62 insertions(+), 0 deletions(-) diff --git a/libvirt-glib/libvirt-glib-error.c b/libvirt-glib/libvirt-glib-error.c index b4d1f93..1fd32f0 100644 --- a/libvirt-glib/libvirt-glib-error.c +++ b/libvirt-glib/libvirt-glib-error.c @@ -126,3 +126,52 @@ GError *gvir_error_new_valist(GQuark domain, return err; } + +/** + * gvir_set_error: (skip) + * @error: a return location for a #GError, or #NULL + * @domain: error domain + * @code: error code + * @format: printf()-style format for error message + * @Varargs: parameters for message format + * + * Does nothing if @error is #NULL; if @error is non-#NULL, then *@error + * must be #NULL. A new #GError is created and assigned to *@error. + */ +void gvir_set_error(GError **error, GQuark domain, gint code, + const gchar *format, ...) +{ + va_list args; + + if (error == NULL) { + return; + } + + va_start(args, format); + *error = gvir_error_new_valist(domain, code, format, args); + va_end(args); +} + +/** + * gvir_set_error_literal: (skip) + * @error: a return location for a #GError, or #NULL + * @domain: error domain + * @code: error code + * @message: error message + * + * Does nothing if @error is #NULL; if @error is non-#NULL, then *@error + * must be #NULL. A new #GError is created and assigned to *@error. + * Unlike g_set_error(), message is not a printf()-style format string. Use + * this function if message contains text you don't have control over, that + * could include printf() escape sequences. + */ + +void gvir_set_error_literal(GError **error, GQuark domain, gint code, + const gchar *message) +{ + if (error == NULL) { + return; + } + + *error = gvir_error_new_literal(domain, code, message); +} diff --git a/libvirt-glib/libvirt-glib-error.h b/libvirt-glib/libvirt-glib-error.h index cfb5b95..aa581e5 100644 --- a/libvirt-glib/libvirt-glib-error.h +++ b/libvirt-glib/libvirt-glib-error.h @@ -42,6 +42,17 @@ GError *gvir_error_new_valist(GQuark domain, const gchar *format, va_list args); +void gvir_set_error(GError **error, + GQuark domain, + gint code, + const gchar *format, + ...); + +void gvir_set_error_literal(GError **error, + GQuark domain, + gint code, + const gchar *message); + G_END_DECLS #endif /* __LIBVIRT_GLIB_ERROR_H__ */ diff --git a/libvirt-glib/libvirt-glib.sym b/libvirt-glib/libvirt-glib.sym index cd41cb9..dca7dbb 100644 --- a/libvirt-glib/libvirt-glib.sym +++ b/libvirt-glib/libvirt-glib.sym @@ -7,6 +7,8 @@ LIBVIRT_GLIB_0.0.1 { gvir_error_new; gvir_error_new_valist; gvir_error_new_literal; + gvir_set_error; + gvir_set_error_literal; local: *; -- 1.7.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list