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 Lesser 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser 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.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
49 typedef FILE* GFileDescriptor;
51 typedef gint GFileDescriptor;
54 /* --- structures --- */
55 typedef struct _GLogDomain GLogDomain;
56 typedef struct _GLogHandler GLogHandler;
60 GLogLevelFlags fatal_mask;
61 GLogHandler *handlers;
67 GLogLevelFlags log_level;
74 /* --- prototypes --- */
75 #ifndef HAVE_C99_VSNPRINTF
76 static gsize printf_string_upper_bound (const gchar *format,
79 #endif /* !HAVE_C99_VSNPRINTF */
82 /* --- variables --- */
83 static GMutex *g_messages_lock = NULL;
84 static GLogDomain *g_log_domains = NULL;
85 static GLogLevelFlags g_log_always_fatal = G_LOG_FATAL_MASK;
86 static GPrintFunc glib_print_func = NULL;
87 static GPrintFunc glib_printerr_func = NULL;
88 static GPrivate *g_log_depth = NULL;
89 static GLogLevelFlags g_log_msg_prefix = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_DEBUG;
92 /* --- functions --- */
97 # include <process.h> /* For _getpid() */
98 static gboolean alloc_console_called = FALSE;
99 static gboolean win32_keep_fatal_message = FALSE;
101 /* This default message will usually be overwritten. */
102 /* Yes, a fixed size buffer is bad. So sue me. But g_error is never
103 * with huge strings, is it?
105 static gchar fatal_msg_buf[1000] = "Unspecified fatal error encountered, aborting.";
106 static gchar *fatal_msg_ptr = fatal_msg_buf;
108 /* Just use stdio. If we're out of memory, we're hosed anyway. */
111 dowrite (GFileDescriptor fd,
115 if (win32_keep_fatal_message)
117 memcpy (fatal_msg_ptr, buf, len);
118 fatal_msg_ptr += len;
123 fwrite (buf, len, 1, fd);
128 #define write(fd, buf, len) dowrite(fd, buf, len)
131 ensure_stdout_valid (void)
135 if (win32_keep_fatal_message)
138 if (!alloc_console_called)
140 handle = GetStdHandle (STD_OUTPUT_HANDLE);
142 if (handle == INVALID_HANDLE_VALUE)
145 alloc_console_called = TRUE;
146 freopen ("CONOUT$", "w", stdout);
151 #define ensure_stdout_valid() /* Define as empty */
155 write_string (GFileDescriptor fd,
158 write (fd, string, strlen (string));
162 g_messages_prefixed_init (void)
164 static gboolean initialized = FALSE;
171 val = g_getenv ("G_MESSAGES_PREFIXED");
175 static const GDebugKey keys[] = {
176 { "error", G_LOG_LEVEL_ERROR },
177 { "critical", G_LOG_LEVEL_CRITICAL },
178 { "warning", G_LOG_LEVEL_WARNING },
179 { "message", G_LOG_LEVEL_MESSAGE },
180 { "info", G_LOG_LEVEL_INFO },
181 { "debug", G_LOG_LEVEL_DEBUG }
184 g_log_msg_prefix = g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
190 g_log_find_domain_L (const gchar *log_domain)
192 register GLogDomain *domain;
194 domain = g_log_domains;
197 if (strcmp (domain->log_domain, log_domain) == 0)
199 domain = domain->next;
205 g_log_domain_new_L (const gchar *log_domain)
207 register GLogDomain *domain;
209 domain = g_new (GLogDomain, 1);
210 domain->log_domain = g_strdup (log_domain);
211 domain->fatal_mask = G_LOG_FATAL_MASK;
212 domain->handlers = NULL;
214 domain->next = g_log_domains;
215 g_log_domains = domain;
221 g_log_domain_check_free_L (GLogDomain *domain)
223 if (domain->fatal_mask == G_LOG_FATAL_MASK &&
224 domain->handlers == NULL)
226 register GLogDomain *last, *work;
230 work = g_log_domains;
236 last->next = domain->next;
238 g_log_domains = domain->next;
239 g_free (domain->log_domain);
250 g_log_domain_get_handler_L (GLogDomain *domain,
251 GLogLevelFlags log_level,
254 if (domain && log_level)
256 register GLogHandler *handler;
258 handler = domain->handlers;
261 if ((handler->log_level & log_level) == log_level)
263 *data = handler->data;
264 return handler->log_func;
266 handler = handler->next;
269 return g_log_default_handler;
273 g_log_set_always_fatal (GLogLevelFlags fatal_mask)
275 GLogLevelFlags old_mask;
277 /* restrict the global mask to levels that are known to glib
278 * since this setting applies to all domains
280 fatal_mask &= (1 << G_LOG_LEVEL_USER_SHIFT) - 1;
281 /* force errors to be fatal */
282 fatal_mask |= G_LOG_LEVEL_ERROR;
283 /* remove bogus flag */
284 fatal_mask &= ~G_LOG_FLAG_FATAL;
286 g_mutex_lock (g_messages_lock);
287 old_mask = g_log_always_fatal;
288 g_log_always_fatal = fatal_mask;
289 g_mutex_unlock (g_messages_lock);
295 g_log_set_fatal_mask (const gchar *log_domain,
296 GLogLevelFlags fatal_mask)
298 GLogLevelFlags old_flags;
299 register GLogDomain *domain;
304 /* force errors to be fatal */
305 fatal_mask |= G_LOG_LEVEL_ERROR;
306 /* remove bogus flag */
307 fatal_mask &= ~G_LOG_FLAG_FATAL;
309 g_mutex_lock (g_messages_lock);
311 domain = g_log_find_domain_L (log_domain);
313 domain = g_log_domain_new_L (log_domain);
314 old_flags = domain->fatal_mask;
316 domain->fatal_mask = fatal_mask;
317 g_log_domain_check_free_L (domain);
319 g_mutex_unlock (g_messages_lock);
325 g_log_set_handler (const gchar *log_domain,
326 GLogLevelFlags log_levels,
330 static guint handler_id = 0;
332 GLogHandler *handler;
334 g_return_val_if_fail ((log_levels & G_LOG_LEVEL_MASK) != 0, 0);
335 g_return_val_if_fail (log_func != NULL, 0);
340 handler = g_new (GLogHandler, 1);
342 g_mutex_lock (g_messages_lock);
344 domain = g_log_find_domain_L (log_domain);
346 domain = g_log_domain_new_L (log_domain);
348 handler->id = ++handler_id;
349 handler->log_level = log_levels;
350 handler->log_func = log_func;
351 handler->data = user_data;
352 handler->next = domain->handlers;
353 domain->handlers = handler;
355 g_mutex_unlock (g_messages_lock);
361 g_log_remove_handler (const gchar *log_domain,
364 register GLogDomain *domain;
366 g_return_if_fail (handler_id > 0);
371 g_mutex_lock (g_messages_lock);
372 domain = g_log_find_domain_L (log_domain);
375 GLogHandler *work, *last;
378 work = domain->handlers;
381 if (work->id == handler_id)
384 last->next = work->next;
386 domain->handlers = work->next;
387 g_log_domain_check_free_L (domain);
388 g_mutex_unlock (g_messages_lock);
396 g_mutex_unlock (g_messages_lock);
397 g_warning ("%s: could not find handler with id `%d' for domain \"%s\"",
398 G_STRLOC, handler_id, log_domain);
402 g_logv (const gchar *log_domain,
403 GLogLevelFlags log_level,
408 gboolean was_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
409 gboolean was_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0;
412 #ifndef HAVE_VSNPRINTF
414 #endif /* HAVE_VSNPRINTF */
416 log_level &= G_LOG_LEVEL_MASK;
420 /* we use a stack buffer of fixed size, because we might get called
423 #ifdef HAVE_VSNPRINTF
424 vsnprintf (buffer, 1024, format, args1);
425 #else /* !HAVE_VSNPRINTF */
426 G_VA_COPY (args2, args1);
427 if (printf_string_upper_bound (format, FALSE, args1) < 1024)
428 vsprintf (buffer, format, args2);
431 /* since we might be out of memory, we can't use g_vsnprintf(). */
432 /* we are out of luck here */
433 strncpy (buffer, format, 1024);
437 #endif /* !HAVE_VSNPRINTF */
439 for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i))
441 register GLogLevelFlags test_level;
444 if (log_level & test_level)
446 guint depth = GPOINTER_TO_UINT (g_private_get (g_log_depth));
449 guint domain_fatal_mask;
450 gpointer data = NULL;
453 test_level |= G_LOG_FLAG_FATAL;
455 test_level |= G_LOG_FLAG_RECURSION;
457 /* check recursion and lookup handler */
458 g_mutex_lock (g_messages_lock);
459 domain = g_log_find_domain_L (log_domain ? log_domain : "");
461 test_level |= G_LOG_FLAG_RECURSION;
463 domain_fatal_mask = domain ? domain->fatal_mask : G_LOG_FATAL_MASK;
464 if ((domain_fatal_mask | g_log_always_fatal) & test_level)
465 test_level |= G_LOG_FLAG_FATAL;
466 if (test_level & G_LOG_FLAG_RECURSION)
467 log_func = _g_log_fallback_handler;
469 log_func = g_log_domain_get_handler_L (domain, test_level, &data);
471 g_mutex_unlock (g_messages_lock);
473 g_private_set (g_log_depth, GUINT_TO_POINTER (depth));
475 /* had to defer debug initialization until we can keep track of recursion */
476 if (!(test_level & G_LOG_FLAG_RECURSION) && !_g_debug_initialized)
478 guint orig_test_level = test_level;
481 if ((domain_fatal_mask | g_log_always_fatal) & test_level)
482 test_level |= G_LOG_FLAG_FATAL;
483 if (test_level != orig_test_level)
485 /* need a relookup, not nice, but not too bad either */
486 g_mutex_lock (g_messages_lock);
487 domain = g_log_find_domain_L (log_domain ? log_domain : "");
488 log_func = g_log_domain_get_handler_L (domain, test_level, &data);
490 g_mutex_unlock (g_messages_lock);
494 log_func (log_domain, test_level, buffer, data);
496 if (test_level & G_LOG_FLAG_FATAL)
499 MessageBox (NULL, fatal_msg_buf, NULL, MB_OK);
501 #if defined (G_ENABLE_DEBUG) && (defined (SIGTRAP) || defined (G_OS_WIN32))
502 if (!(test_level & G_LOG_FLAG_RECURSION))
506 #else /* !G_ENABLE_DEBUG || !(SIGTRAP || G_OS_WIN32) */
508 #endif /* !G_ENABLE_DEBUG || !(SIGTRAP || G_OS_WIN32) */
512 g_private_set (g_log_depth, GUINT_TO_POINTER (depth));
518 g_log (const gchar *log_domain,
519 GLogLevelFlags log_level,
525 va_start (args, format);
526 g_logv (log_domain, log_level, format, args);
531 strdup_convert (const gchar *string,
532 const gchar *charset)
534 if (!g_utf8_validate (string, -1, NULL))
535 return g_strconcat ("[Invalid UTF-8] ", string, NULL);
537 return g_convert_with_fallback (string, -1, charset, "UTF-8", "?", NULL, NULL, NULL);
540 /* For a radix of 8 we need at most 3 output bytes for 1 input
541 * byte. Additionally we might need up to 2 output bytes for the
542 * readix prefix and 1 byte for the trailing NULL.
544 #define FORMAT_UNSIGNED_BUFSIZE ((GLIB_SIZEOF_LONG * 3) + 3)
547 format_unsigned (gchar *buf,
555 /* we may not call _any_ GLib functions here (or macros like g_return_if_fail()) */
557 if (radix != 8 && radix != 10 && radix != 16)
590 /* Again we can't use g_assert; actually this check should _never_ fail. */
591 if (n > FORMAT_UNSIGNED_BUFSIZE - 3)
604 buf[i] = c + 'a' - 10;
611 /* string size big enough to hold level prefix */
612 #define STRING_BUFFER_SIZE (FORMAT_UNSIGNED_BUFSIZE + 32)
614 #define ALERT_LEVELS (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING)
616 static GFileDescriptor
617 mklevel_prefix (gchar level_prefix[STRING_BUFFER_SIZE],
620 gboolean to_stdout = TRUE;
622 /* we may not call _any_ GLib functions here */
624 switch (log_level & G_LOG_LEVEL_MASK)
626 case G_LOG_LEVEL_ERROR:
627 strcpy (level_prefix, "ERROR");
630 case G_LOG_LEVEL_CRITICAL:
631 strcpy (level_prefix, "CRITICAL");
634 case G_LOG_LEVEL_WARNING:
635 strcpy (level_prefix, "WARNING");
638 case G_LOG_LEVEL_MESSAGE:
639 strcpy (level_prefix, "Message");
642 case G_LOG_LEVEL_INFO:
643 strcpy (level_prefix, "INFO");
645 case G_LOG_LEVEL_DEBUG:
646 strcpy (level_prefix, "DEBUG");
651 strcpy (level_prefix, "LOG-");
652 format_unsigned (level_prefix + 4, log_level & G_LOG_LEVEL_MASK, 16);
655 strcpy (level_prefix, "LOG");
658 if (log_level & G_LOG_FLAG_RECURSION)
659 strcat (level_prefix, " (recursed)");
660 if (log_level & ALERT_LEVELS)
661 strcat (level_prefix, " **");
663 ensure_stdout_valid ();
665 win32_keep_fatal_message = (log_level & G_LOG_FLAG_FATAL) != 0;
666 /* Use just stdout as stderr is hard to get redirected from the DOS prompt. */
669 return to_stdout ? 1 : 2;
674 _g_log_fallback_handler (const gchar *log_domain,
675 GLogLevelFlags log_level,
676 const gchar *message,
677 gpointer unused_data)
679 gchar level_prefix[STRING_BUFFER_SIZE], pid_string[FORMAT_UNSIGNED_BUFSIZE];
680 gboolean is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
683 /* we can not call _any_ GLib functions in this fallback handler,
684 * which is why we skip UTF-8 conversion, etc.
685 * since we either recursed or ran out of memory, we're in a pretty
686 * pathologic situation anyways, what we can do is giving the
687 * the process ID unconditionally however.
690 fd = mklevel_prefix (level_prefix, log_level);
692 message = "(NULL) message";
694 format_unsigned (pid_string, getpid (), 10);
697 write_string (fd, "\n");
699 write_string (fd, "\n** ");
700 write_string (fd, "(process:");
701 write_string (fd, pid_string);
702 write_string (fd, "): ");
705 write_string (fd, log_domain);
706 write_string (fd, "-");
708 write_string (fd, level_prefix);
709 write_string (fd, ": ");
710 write_string (fd, message);
712 write_string (fd, "\naborting...\n");
714 write_string (fd, "\n");
718 g_log_default_handler (const gchar *log_domain,
719 GLogLevelFlags log_level,
720 const gchar *message,
721 gpointer unused_data)
723 gboolean is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
724 gchar level_prefix[STRING_BUFFER_SIZE], *string;
728 /* we can be called externally with recursion for whatever reason */
729 if (log_level & G_LOG_FLAG_RECURSION)
731 _g_log_fallback_handler (log_domain, log_level, message, unused_data);
735 g_messages_prefixed_init ();
737 fd = mklevel_prefix (level_prefix, log_level);
739 gstring = g_string_new ("");
740 if (log_level & ALERT_LEVELS)
741 g_string_append (gstring, "\n");
743 g_string_append (gstring, "** ");
745 if ((g_log_msg_prefix & log_level) == log_level)
747 const gchar *prg_name = g_get_prgname ();
750 g_string_append_printf (gstring, "(process:%lu): ", (gulong)getpid ());
752 g_string_append_printf (gstring, "(%s:%lu): ", prg_name, (gulong)getpid ());
757 g_string_append (gstring, log_domain);
758 g_string_append_c (gstring, '-');
760 g_string_append (gstring, level_prefix);
762 g_string_append (gstring, ": ");
764 g_string_append (gstring, "(NULL) message");
767 const gchar *charset;
769 if (g_get_charset (&charset))
770 g_string_append (gstring, message); /* charset is UTF-8 already */
773 string = strdup_convert (message, charset);
774 g_string_append (gstring, string);
779 g_string_append (gstring, "\naborting...\n");
781 g_string_append (gstring, "\n");
783 string = g_string_free (gstring, FALSE);
785 write_string (fd, string);
790 g_set_print_handler (GPrintFunc func)
792 GPrintFunc old_print_func;
794 g_mutex_lock (g_messages_lock);
795 old_print_func = glib_print_func;
796 glib_print_func = func;
797 g_mutex_unlock (g_messages_lock);
799 return old_print_func;
803 g_print (const gchar *format,
808 GPrintFunc local_glib_print_func;
810 g_return_if_fail (format != NULL);
812 va_start (args, format);
813 string = g_strdup_vprintf (format, args);
816 g_mutex_lock (g_messages_lock);
817 local_glib_print_func = glib_print_func;
818 g_mutex_unlock (g_messages_lock);
820 if (local_glib_print_func)
821 local_glib_print_func (string);
824 const gchar *charset;
826 ensure_stdout_valid ();
827 if (g_get_charset (&charset))
828 fputs (string, stdout); /* charset is UTF-8 already */
831 gchar *lstring = strdup_convert (string, charset);
833 fputs (lstring, stdout);
842 g_set_printerr_handler (GPrintFunc func)
844 GPrintFunc old_printerr_func;
846 g_mutex_lock (g_messages_lock);
847 old_printerr_func = glib_printerr_func;
848 glib_printerr_func = func;
849 g_mutex_unlock (g_messages_lock);
851 return old_printerr_func;
855 g_printerr (const gchar *format,
860 GPrintFunc local_glib_printerr_func;
862 g_return_if_fail (format != NULL);
864 va_start (args, format);
865 string = g_strdup_vprintf (format, args);
868 g_mutex_lock (g_messages_lock);
869 local_glib_printerr_func = glib_printerr_func;
870 g_mutex_unlock (g_messages_lock);
872 if (local_glib_printerr_func)
873 local_glib_printerr_func (string);
876 const gchar *charset;
878 if (g_get_charset (&charset))
879 fputs (string, stderr); /* charset is UTF-8 already */
882 gchar *lstring = strdup_convert (string, charset);
884 fputs (lstring, stderr);
893 # define MB_LEN_MAX 8
896 #ifndef HAVE_C99_VSNPRINTF
902 gboolean alternate_format, zero_padding, adjust_left, locale_grouping;
903 gboolean add_space, add_sign, possible_sign, seen_precision;
904 gboolean mod_half, mod_long, mod_extra_long;
908 printf_string_upper_bound (const gchar *format,
912 static const gboolean honour_longs = SIZEOF_LONG > 4 || SIZEOF_VOID_P > 4;
920 register gchar c = *format++;
924 else /* (c == '%') */
926 PrintfArgSpec spec = { 0, };
927 gboolean seen_l = FALSE, conv_done = FALSE;
929 const gchar *spec_start = format;
936 GDoubleIEEE754 u_double;
939 const gchar *v_string;
941 /* beware of positional parameters
945 g_warning (G_GNUC_PRETTY_FUNCTION
946 "(): unable to handle positional parameters (%%n$)");
947 len += 1024; /* try adding some safety padding */
954 spec.alternate_format = TRUE;
957 spec.zero_padding = TRUE;
960 spec.adjust_left = TRUE;
963 spec.add_space = TRUE;
966 spec.add_sign = TRUE;
969 spec.locale_grouping = TRUE;
972 /* parse output size specifications
975 spec.seen_precision = TRUE;
988 while (c >= '0' && c <= '9')
991 v_uint = v_uint * 10 + c - '0';
994 if (spec.seen_precision)
995 spec.precision = MAX (spec.precision, v_uint);
997 spec.min_width = MAX (spec.min_width, v_uint);
1000 v_int = va_arg (args, int);
1001 if (spec.seen_precision)
1003 /* forget about negative precision */
1005 spec.precision = MAX (spec.precision, v_int);
1012 spec.adjust_left = TRUE;
1014 spec.min_width = MAX (spec.min_width, v_int);
1018 /* parse type modifiers
1021 spec.mod_half = TRUE;
1026 spec.mod_long = TRUE;
1030 /* else, fall through */
1033 spec.mod_long = TRUE;
1034 spec.mod_extra_long = TRUE;
1038 #if GLIB_SIZEOF_SIZE_T > 4
1039 spec.mod_long = TRUE;
1040 spec.mod_extra_long = TRUE;
1041 #endif /* GLIB_SIZEOF_SIZE_T > 4 */
1044 #if GLIB_SIZEOF_PTRDIFF_T > 4
1045 spec.mod_long = TRUE;
1046 spec.mod_extra_long = TRUE;
1047 #endif /* GLIB_SIZEOF_PTRDIFF_T > 4 */
1050 #if GLIB_SIZEOF_INTMAX_T > 4
1051 spec.mod_long = TRUE;
1052 spec.mod_extra_long = TRUE;
1053 #endif /* GLIB_SIZEOF_INTMAX_T > 4 */
1056 /* parse output conversions
1065 /* some C libraries feature long variants for these as well? */
1066 spec.mod_long = TRUE;
1073 conv_len += 1; /* sign */
1080 spec.possible_sign = TRUE;
1082 if (spec.mod_long && honour_longs)
1084 if (spec.mod_extra_long)
1086 if (spec.mod_extra_long)
1088 (void) va_arg (args, gint64);
1090 else if (spec.mod_long)
1091 (void) va_arg (args, long);
1093 (void) va_arg (args, int);
1105 spec.possible_sign = TRUE;
1106 /* n . dddddddddddddddddddddddd E +- eeee */
1107 conv_len += 1 + 1 + MAX (24, spec.precision) + 1 + 1 + 4;
1108 if (may_warn && spec.mod_extra_long)
1109 g_warning (G_GNUC_PRETTY_FUNCTION
1110 "(): unable to handle long double, collecting double only");
1111 #ifdef HAVE_LONG_DOUBLE
1112 #error need to implement special handling for long double
1114 u_double.v_double = va_arg (args, double);
1115 /* %f can expand up to all significant digits before '.' (308) */
1117 u_double.mpn.biased_exponent > 0 && u_double.mpn.biased_exponent < 2047)
1119 gint exp = u_double.mpn.biased_exponent;
1121 exp -= G_IEEE754_DOUBLE_BIAS;
1122 exp = exp * G_LOG_2_BASE_10 + 1;
1123 conv_len += ABS (exp); /* exp can be <0 */
1125 /* some printf() implementations require extra padding for rounding */
1127 /* we can't really handle locale specific grouping here */
1128 if (spec.locale_grouping)
1132 spec.mod_long = TRUE;
1135 conv_len += spec.mod_long ? MB_LEN_MAX : 1;
1136 (void) va_arg (args, int);
1139 spec.mod_long = TRUE;
1142 v_string = va_arg (args, char*);
1144 conv_len += 8; /* hold "(null)" */
1145 else if (spec.seen_precision)
1146 conv_len += spec.precision;
1148 conv_len += strlen (v_string);
1153 g_warning (G_GNUC_PRETTY_FUNCTION
1154 "(): unable to handle wide char strings");
1155 len += 1024; /* try adding some safety padding */
1158 case 'P': /* do we actually need this? */
1161 spec.alternate_format = TRUE;
1168 (void) va_arg (args, void*);
1171 /* there's not much we can do to be clever */
1172 v_string = g_strerror (errno);
1173 v_uint = v_string ? strlen (v_string) : 0;
1174 conv_len += MAX (256, v_uint);
1177 /* handle invalid cases
1180 /* no conversion specification, bad bad */
1181 conv_len += format - spec_start;
1185 g_warning (G_GNUC_PRETTY_FUNCTION
1186 "(): unable to handle `%c' while parsing format",
1190 conv_done |= conv_len > 0;
1193 /* handle width specifications */
1194 conv_len = MAX (conv_len, MAX (spec.precision, spec.min_width));
1196 conv_len += spec.alternate_format ? 2 : 0;
1197 conv_len += (spec.add_space || spec.add_sign || spec.possible_sign);
1200 } /* else (c == '%') */
1201 } /* while (*format) */
1206 #endif /* !HAVE_C99_VSNPRINTF */
1210 g_printf_string_upper_bound (const gchar *format,
1213 #if HAVE_C99_VSNPRINTF
1215 return vsnprintf (&c, 1, format, args) + 1;
1217 return printf_string_upper_bound (format, TRUE, args);
1222 g_messages_init (void)
1224 g_messages_lock = g_mutex_new ();
1225 g_log_depth = g_private_new (NULL);
1226 g_messages_prefixed_init ();
1230 gboolean _g_debug_initialized = FALSE;
1231 guint _g_debug_flags = 0;
1234 _g_debug_init (void)
1238 _g_debug_initialized = TRUE;
1240 val = g_getenv ("G_DEBUG");
1243 static const GDebugKey keys[] = {
1244 {"fatal_warnings", G_DEBUG_FATAL_WARNINGS}
1247 _g_debug_flags = g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
1250 if (_g_debug_flags & G_DEBUG_FATAL_WARNINGS)
1252 GLogLevelFlags fatal_mask;
1254 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
1255 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
1256 g_log_set_always_fatal (fatal_mask);