diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 83a9a8e9a..cf5f2ce1b 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -786,6 +786,7 @@ g_set_error_literal g_propagate_error g_clear_error g_prefix_error +g_prefix_error_literal g_propagate_prefixed_error GErrorInitFunc diff --git a/glib/gerror.c b/glib/gerror.c index 222db1cc2..bd5408872 100644 --- a/glib/gerror.c +++ b/glib/gerror.c @@ -1100,6 +1100,30 @@ g_prefix_error (GError **err, } } +/** + * g_prefix_error_literal: + * @err: (allow-none): a return location for a #GError, or %NULL + * @prefix: string to prefix @err with + * + * Prefixes @prefix to an existing error message. If @err or *@err is + * %NULL (i.e.: no error variable) then do nothing. + * + * Since: 2.70 + */ +void +g_prefix_error_literal (GError **err, + const gchar *prefix) +{ + if (err && *err) + { + gchar *oldstring; + + oldstring = (*err)->message; + (*err)->message = g_strconcat (prefix, oldstring, NULL); + g_free (oldstring); + } +} + /** * g_propagate_prefixed_error: * @dest: error return location diff --git a/glib/gerror.h b/glib/gerror.h index 6431d5b6c..bc9c03a91 100644 --- a/glib/gerror.h +++ b/glib/gerror.h @@ -244,6 +244,11 @@ void g_prefix_error (GError **err, const gchar *format, ...) G_GNUC_PRINTF (2, 3); +/* if (err) prefix the string to the ->message */ +GLIB_AVAILABLE_IN_2_70 +void g_prefix_error_literal (GError **err, + const gchar *prefix); + /* g_propagate_error then g_error_prefix on dest */ GLIB_AVAILABLE_IN_ALL void g_propagate_prefixed_error (GError **dest,