1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 static GErrorFunc glib_error_func = NULL;
27 static GWarningFunc glib_warning_func = NULL;
28 static GPrintFunc glib_message_func = NULL;
29 static GPrintFunc glib_print_func = NULL;
31 extern char* g_vsprintf (const gchar *fmt, va_list *args, va_list *args2);
34 g_error (const gchar *format, ...)
38 static gboolean errored = 0;
42 write (2, "g_error: recursed!\n", 19);
46 va_start (args, format);
47 va_start (args2, format);
48 buf = g_vsprintf (format, &args, &args2);
54 (* glib_error_func) (buf);
58 /* Use write() here because we might be out of memory */
59 write (2, "\n** ERROR **: ", 14);
60 write (2, buf, strlen(buf));
68 g_warning (const gchar *format, ...)
73 va_start (args, format);
74 va_start (args2, format);
75 buf = g_vsprintf (format, &args, &args2);
79 if (glib_warning_func)
81 (* glib_warning_func) (buf);
85 fputs ("\n** WARNING **: ", stderr);
92 g_message (const gchar *format, ...)
97 va_start (args, format);
98 va_start (args2, format);
99 buf = g_vsprintf (format, &args, &args2);
103 if (glib_message_func)
105 (* glib_message_func) (buf);
109 fputs ("message: ", stdout);
111 fputc ('\n', stdout);
116 g_print (const gchar *format, ...)
121 va_start (args, format);
122 va_start (args2, format);
123 buf = g_vsprintf (format, &args, &args2);
129 (* glib_print_func) (buf);
138 g_set_error_handler (GErrorFunc func)
140 GErrorFunc old_error_func;
142 old_error_func = glib_error_func;
143 glib_error_func = func;
145 return old_error_func;
149 g_set_warning_handler (GWarningFunc func)
151 GWarningFunc old_warning_func;
153 old_warning_func = glib_warning_func;
154 glib_warning_func = func;
156 return old_warning_func;
160 g_set_message_handler (GPrintFunc func)
162 GPrintFunc old_message_func;
164 old_message_func = glib_message_func;
165 glib_message_func = func;
167 return old_message_func;
171 g_set_print_handler (GPrintFunc func)
173 GPrintFunc old_print_func;
175 old_print_func = glib_print_func;
176 glib_print_func = func;
178 return old_print_func;