Commit f2a5aa67 authored by Allison Karlitskaya's avatar Allison Karlitskaya Committed by Ryan Lortie

new functions g_prefix_error and g_propagate_prefixed_error.

2006-11-15  Ryan Lortie  <desrt@desrt.ca>

        * docs/reference/glib/glib-sections.txt:
        * glib/glib.symbols:
        * glib/gerror.h:
        * glib/gerror.c: new functions g_prefix_error and
        g_propagate_prefixed_error.


svn path=/trunk/; revision=5859
parent 2eca1b52
2006-11-15 Ryan Lortie <desrt@desrt.ca>
* docs/reference/glib/glib-sections.txt:
* glib/glib.symbols:
* glib/gerror.h:
* glib/gerror.c: new functions g_prefix_error and
g_propagate_prefixed_error.
2007-11-13 Cody Russell <bratsche@gnome.org>
* docs/reference/gobject/gobject-docs.sgml:
......
......@@ -386,6 +386,8 @@ g_error_matches
g_set_error
g_propagate_error
g_clear_error
g_prefix_error
g_propagate_prefixed_error
</SECTION>
<SECTION>
......
......@@ -257,5 +257,82 @@ g_clear_error (GError **err)
}
}
static void
g_error_add_prefix (gchar **string,
const gchar *format,
va_list ap)
{
gchar *oldstring;
gchar *prefix;
prefix = g_strdup_vprintf (format, ap);
oldstring = *string;
*string = g_strjoin ("", prefix, oldstring, NULL);
g_free (oldstring);
g_free (prefix);
}
/**
* g_prefix_error:
* @err: a return location for a #GError, or %NULL
* @format: printf()-style format string
* ...: arguments to @format
*
* Formats a string according to @format and
* prefix it to an existing error message. If
* @err is %NULL (ie: no error variable) then do
* nothing.
*
* If *@err is %NULL (ie: an error variable is
* present but there is no error condition) then
* also do nothing. Whether or not it makes
* sense to take advantage of this feature is up
* to you.
**/
void
g_prefix_error (GError **err,
const gchar *format,
...)
{
if (err && *err)
{
va_list ap;
va_start (ap, format);
g_error_add_prefix (&(*err)->message, format, ap);
va_end (ap);
}
}
/**
* g_propagate_prefixed_error:
* @dest: error return location
* @src: error to move into the return location
* @format: printf()-style format string
* ...: arguments to @format
*
* If @dest is %NULL, free @src; otherwise,
* moves @src into *@dest. *@dest must be %NULL.
* After the move, add a prefix as with
* g_prefix_error().
**/
void
g_propagate_prefixed_error (GError **dest,
GError *src,
const gchar *format,
...)
{
g_propagate_error (dest, src);
if (dest && *dest)
{
va_list ap;
va_start (ap, format);
g_error_add_prefix (&(*dest)->message, format, ap);
va_end (ap);
}
}
#define __G_ERROR_C__
#include "galiasdef.c"
......@@ -67,6 +67,16 @@ void g_propagate_error (GError **dest,
/* if (err && *err) { g_error_free(*err); *err = NULL; } */
void g_clear_error (GError **err);
/* if (err) prefix the formatted string to the ->message */
void g_prefix_error (GError **err,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
/* g_propagate_error then g_error_prefix on dest */
void g_propagate_prefixed_error (GError **dest,
GError *src,
const gchar *format,
...) G_GNUC_PRINTF (3, 4);
G_END_DECLS
......
......@@ -320,6 +320,8 @@ g_error_new G_GNUC_PRINTF(3,4)
g_error_new_literal
g_propagate_error
g_set_error G_GNUC_PRINTF(4,5)
g_prefix_error G_GNUC_PRINTF(2,3)
g_propagate_prefixed_error G_GNUC_PRINTF(3,4)
#endif
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment