[glib: 1/3] Add g_prefix_error_literal()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/3] Add g_prefix_error_literal()
- Date: Tue, 1 Jun 2021 19:08:18 +0000 (UTC)
commit 9cb1bb0fb24be404734aeaf0f53e745cbea88355
Author: Dan Williams <dcbw redhat com>
Date: Thu May 27 13:29:54 2021 +0200
Add g_prefix_error_literal()
Because sometimes you don't want a lone "%s", and you don't
want the compiler yelling at you about format strings that
don't have any format in them.
Closes #663
docs/reference/glib/glib-sections.txt | 1 +
glib/gerror.c | 24 ++++++++++++++++++++++++
glib/gerror.h | 5 +++++
3 files changed, 30 insertions(+)
---
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
<SUBSECTION>
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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]