From 99c0940b7894a32246d190a70fb348e326b4fa50 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 4 Jun 2003 22:49:08 +0000 Subject: [PATCH] Use the current g_file_get_contents() as example. --- docs/reference/glib/tmpl/error_reporting.sgml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/reference/glib/tmpl/error_reporting.sgml b/docs/reference/glib/tmpl/error_reporting.sgml index c78bc87..4174733 100644 --- a/docs/reference/glib/tmpl/error_reporting.sgml +++ b/docs/reference/glib/tmpl/error_reporting.sgml @@ -39,14 +39,17 @@ This is why most functions in GLib and GTK+ do not use the #GError facility. Functions that can fail take a return location for a #GError as their last argument. For example: -gchar* g_file_get_contents (const gchar *filename, GError **error); +gboolean g_file_get_contents (const gchar *filename, + gchar **contents, + gsize *length, + GError **error); If you pass a non-%NULL value for the error argument, it should point to a location where an error can be placed. For example: gchar *contents; GError *err = NULL; -contents = g_file_get_contents ("foo.txt", &err); +g_file_get_contents ("foo.txt", &contents, NULL, &err); g_assert ((contents == NULL && err != NULL) || (contents != NULL && err == NULL)); if (err != NULL) { @@ -63,18 +66,16 @@ else Note that err != NULL in this example is a reliable indicator of whether -g_file_get_contents() failed. Also, g_file_get_contents() uses the -convention that a %NULL return value means an error occurred (but not -all functions use this convention). +g_file_get_contents() failed. Additionally, g_file_get_contents() returns +a boolean which indicates whether it was successful. -Because g_file_get_contents() returns %NULL on failure, if you are only +Because g_file_get_contents() returns %FALSE on failure, if you are only interested in whether it failed and don't need to display an error message, you can pass %NULL for the error argument: -contents = g_file_get_contents ("foo.txt", NULL); /* ignore errors */ -if (contents != NULL) +if (g_file_get_contents ("foo.txt", &contents, NULL, NULL)) /* ignore errors */ /* no error occurred */ ; else /* error */ ; -- 2.7.4