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);
530 /* For a radix of 8 we need at most 3 output bytes for 1 input
531 * byte. Additionally we might need up to 2 output bytes for the
532 * readix prefix and 1 byte for the trailing NULL.
534 #define FORMAT_UNSIGNED_BUFSIZE ((GLIB_SIZEOF_LONG * 3) + 3)
537 format_unsigned (gchar *buf,
545 /* we may not call _any_ GLib functions here (or macros like g_return_if_fail()) */
547 if (radix != 8 && radix != 10 && radix != 16)
580 /* Again we can't use g_assert; actually this check should _never_ fail. */
581 if (n > FORMAT_UNSIGNED_BUFSIZE - 3)
594 buf[i] = c + 'a' - 10;
601 /* string size big enough to hold level prefix */
602 #define STRING_BUFFER_SIZE (FORMAT_UNSIGNED_BUFSIZE + 32)
604 #define ALERT_LEVELS (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING)
606 static GFileDescriptor
607 mklevel_prefix (gchar level_prefix[STRING_BUFFER_SIZE],
610 gboolean to_stdout = TRUE;
612 /* we may not call _any_ GLib functions here */
614 switch (log_level & G_LOG_LEVEL_MASK)
616 case G_LOG_LEVEL_ERROR:
617 strcpy (level_prefix, "ERROR");
620 case G_LOG_LEVEL_CRITICAL:
621 strcpy (level_prefix, "CRITICAL");
624 case G_LOG_LEVEL_WARNING:
625 strcpy (level_prefix, "WARNING");
628 case G_LOG_LEVEL_MESSAGE:
629 strcpy (level_prefix, "Message");
632 case G_LOG_LEVEL_INFO:
633 strcpy (level_prefix, "INFO");
635 case G_LOG_LEVEL_DEBUG:
636 strcpy (level_prefix, "DEBUG");
641 strcpy (level_prefix, "LOG-");
642 format_unsigned (level_prefix + 4, log_level & G_LOG_LEVEL_MASK, 16);
645 strcpy (level_prefix, "LOG");
648 if (log_level & G_LOG_FLAG_RECURSION)
649 strcat (level_prefix, " (recursed)");
650 if (log_level & ALERT_LEVELS)
651 strcat (level_prefix, " **");
653 ensure_stdout_valid ();
655 win32_keep_fatal_message = (log_level & G_LOG_FLAG_FATAL) != 0;
656 /* Use just stdout as stderr is hard to get redirected from the DOS prompt. */
659 return to_stdout ? 1 : 2;
664 _g_log_fallback_handler (const gchar *log_domain,
665 GLogLevelFlags log_level,
666 const gchar *message,
667 gpointer unused_data)
669 gchar level_prefix[STRING_BUFFER_SIZE], pid_string[FORMAT_UNSIGNED_BUFSIZE];
670 gboolean is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
673 /* we can not call _any_ GLib functions in this fallback handler,
674 * which is why we skip UTF-8 conversion, etc.
675 * since we either recursed or ran out of memory, we're in a pretty
676 * pathologic situation anyways, what we can do is giving the
677 * the process ID unconditionally however.
680 fd = mklevel_prefix (level_prefix, log_level);
682 message = "(NULL) message";
684 format_unsigned (pid_string, getpid (), 10);
687 write_string (fd, "\n");
689 write_string (fd, "\n** ");
690 write_string (fd, "(process:");
691 write_string (fd, pid_string);
692 write_string (fd, "): ");
695 write_string (fd, log_domain);
696 write_string (fd, "-");
698 write_string (fd, level_prefix);
699 write_string (fd, ": ");
700 write_string (fd, message);
702 write_string (fd, "\naborting...\n");
704 write_string (fd, "\n");
708 g_log_default_handler (const gchar *log_domain,
709 GLogLevelFlags log_level,
710 const gchar *message,
711 gpointer unused_data)
713 gboolean is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
714 gchar level_prefix[STRING_BUFFER_SIZE], *string;
718 /* we can be called externally with recursion for whatever reason */
719 if (log_level & G_LOG_FLAG_RECURSION)
721 _g_log_fallback_handler (log_domain, log_level, message, unused_data);
725 g_messages_prefixed_init ();
727 fd = mklevel_prefix (level_prefix, log_level);
729 gstring = g_string_new ("");
730 if (log_level & ALERT_LEVELS)
731 g_string_append (gstring, "\n");
733 g_string_append (gstring, "** ");
735 if ((g_log_msg_prefix & log_level) == log_level)
737 const gchar *prg_name = g_get_prgname ();
740 g_string_append_printf (gstring, "(process:%u): ", getpid ());
742 g_string_append_printf (gstring, "(%s:%u): ", prg_name, getpid ());
747 g_string_append (gstring, log_domain);
748 g_string_append_c (gstring, '-');
750 g_string_append (gstring, level_prefix);
752 g_string_append (gstring, ": ");
754 g_string_append (gstring, "(NULL) message");
757 const gchar *charset;
759 if (g_get_charset (&charset))
760 g_string_append (gstring, message); /* charset is UTF-8 already */
763 if (!g_utf8_validate (message, -1, NULL))
765 g_string_append (gstring, "[Invalid UTF-8] ");
766 g_string_append (gstring, message);
770 string = g_convert_with_fallback (message, -1, charset, "UTF-8",
771 ".", NULL, NULL, NULL);
772 g_string_append (gstring, string);
778 g_string_append (gstring, "\naborting...\n");
780 g_string_append (gstring, "\n");
782 string = g_string_free (gstring, FALSE);
784 write_string (fd, string);
789 g_set_print_handler (GPrintFunc func)
791 GPrintFunc old_print_func;
793 g_mutex_lock (g_messages_lock);
794 old_print_func = glib_print_func;
795 glib_print_func = func;
796 g_mutex_unlock (g_messages_lock);
798 return old_print_func;
802 g_print (const gchar *format,
807 GPrintFunc local_glib_print_func;
809 g_return_if_fail (format != NULL);
811 va_start (args, format);
812 string = g_strdup_vprintf (format, args);
815 g_mutex_lock (g_messages_lock);
816 local_glib_print_func = glib_print_func;
817 g_mutex_unlock (g_messages_lock);
819 if (local_glib_print_func)
820 local_glib_print_func (string);
823 ensure_stdout_valid ();
824 fputs (string, stdout);
831 g_set_printerr_handler (GPrintFunc func)
833 GPrintFunc old_printerr_func;
835 g_mutex_lock (g_messages_lock);
836 old_printerr_func = glib_printerr_func;
837 glib_printerr_func = func;
838 g_mutex_unlock (g_messages_lock);
840 return old_printerr_func;
844 g_printerr (const gchar *format,
849 GPrintFunc local_glib_printerr_func;
851 g_return_if_fail (format != NULL);
853 va_start (args, format);
854 string = g_strdup_vprintf (format, args);
857 g_mutex_lock (g_messages_lock);
858 local_glib_printerr_func = glib_printerr_func;
859 g_mutex_unlock (g_messages_lock);
861 if (local_glib_printerr_func)
862 local_glib_printerr_func (string);
865 fputs (string, stderr);
872 # define MB_LEN_MAX 8
875 #ifndef HAVE_C99_VSNPRINTF
881 gboolean alternate_format, zero_padding, adjust_left, locale_grouping;
882 gboolean add_space, add_sign, possible_sign, seen_precision;
883 gboolean mod_half, mod_long, mod_extra_long;
887 printf_string_upper_bound (const gchar *format,
891 static const gboolean honour_longs = SIZEOF_LONG > 4 || SIZEOF_VOID_P > 4;
899 register gchar c = *format++;
903 else /* (c == '%') */
905 PrintfArgSpec spec = { 0, };
906 gboolean seen_l = FALSE, conv_done = FALSE;
908 const gchar *spec_start = format;
915 GDoubleIEEE754 u_double;
918 const gchar *v_string;
920 /* beware of positional parameters
924 g_warning (G_GNUC_PRETTY_FUNCTION
925 "(): unable to handle positional parameters (%%n$)");
926 len += 1024; /* try adding some safety padding */
933 spec.alternate_format = TRUE;
936 spec.zero_padding = TRUE;
939 spec.adjust_left = TRUE;
942 spec.add_space = TRUE;
945 spec.add_sign = TRUE;
948 spec.locale_grouping = TRUE;
951 /* parse output size specifications
954 spec.seen_precision = TRUE;
967 while (c >= '0' && c <= '9')
970 v_uint = v_uint * 10 + c - '0';
973 if (spec.seen_precision)
974 spec.precision = MAX (spec.precision, v_uint);
976 spec.min_width = MAX (spec.min_width, v_uint);
979 v_int = va_arg (args, int);
980 if (spec.seen_precision)
982 /* forget about negative precision */
984 spec.precision = MAX (spec.precision, v_int);
991 spec.adjust_left = TRUE;
993 spec.min_width = MAX (spec.min_width, v_int);
997 /* parse type modifiers
1000 spec.mod_half = TRUE;
1005 spec.mod_long = TRUE;
1009 /* else, fall through */
1012 spec.mod_long = TRUE;
1013 spec.mod_extra_long = TRUE;
1017 #if GLIB_SIZEOF_SIZE_T > 4
1018 spec.mod_long = TRUE;
1019 spec.mod_extra_long = TRUE;
1020 #endif /* GLIB_SIZEOF_SIZE_T > 4 */
1023 #if GLIB_SIZEOF_PTRDIFF_T > 4
1024 spec.mod_long = TRUE;
1025 spec.mod_extra_long = TRUE;
1026 #endif /* GLIB_SIZEOF_PTRDIFF_T > 4 */
1029 #if GLIB_SIZEOF_INTMAX_T > 4
1030 spec.mod_long = TRUE;
1031 spec.mod_extra_long = TRUE;
1032 #endif /* GLIB_SIZEOF_INTMAX_T > 4 */
1035 /* parse output conversions
1044 /* some C libraries feature long variants for these as well? */
1045 spec.mod_long = TRUE;
1052 conv_len += 1; /* sign */
1059 spec.possible_sign = TRUE;
1061 if (spec.mod_long && honour_longs)
1063 if (spec.mod_extra_long)
1065 if (spec.mod_extra_long)
1067 (void) va_arg (args, gint64);
1069 else if (spec.mod_long)
1070 (void) va_arg (args, long);
1072 (void) va_arg (args, int);
1084 spec.possible_sign = TRUE;
1085 /* n . dddddddddddddddddddddddd E +- eeee */
1086 conv_len += 1 + 1 + MAX (24, spec.precision) + 1 + 1 + 4;
1087 if (may_warn && spec.mod_extra_long)
1088 g_warning (G_GNUC_PRETTY_FUNCTION
1089 "(): unable to handle long double, collecting double only");
1090 #ifdef HAVE_LONG_DOUBLE
1091 #error need to implement special handling for long double
1093 u_double.v_double = va_arg (args, double);
1094 /* %f can expand up to all significant digits before '.' (308) */
1096 u_double.mpn.biased_exponent > 0 && u_double.mpn.biased_exponent < 2047)
1098 gint exp = u_double.mpn.biased_exponent;
1100 exp -= G_IEEE754_DOUBLE_BIAS;
1101 exp = exp * G_LOG_2_BASE_10 + 1;
1102 conv_len += ABS (exp); /* exp can be <0 */
1104 /* some printf() implementations require extra padding for rounding */
1106 /* we can't really handle locale specific grouping here */
1107 if (spec.locale_grouping)
1111 spec.mod_long = TRUE;
1114 conv_len += spec.mod_long ? MB_LEN_MAX : 1;
1115 (void) va_arg (args, int);
1118 spec.mod_long = TRUE;
1121 v_string = va_arg (args, char*);
1123 conv_len += 8; /* hold "(null)" */
1124 else if (spec.seen_precision)
1125 conv_len += spec.precision;
1127 conv_len += strlen (v_string);
1132 g_warning (G_GNUC_PRETTY_FUNCTION
1133 "(): unable to handle wide char strings");
1134 len += 1024; /* try adding some safety padding */
1137 case 'P': /* do we actually need this? */
1140 spec.alternate_format = TRUE;
1147 (void) va_arg (args, void*);
1150 /* there's not much we can do to be clever */
1151 v_string = g_strerror (errno);
1152 v_uint = v_string ? strlen (v_string) : 0;
1153 conv_len += MAX (256, v_uint);
1156 /* handle invalid cases
1159 /* no conversion specification, bad bad */
1160 conv_len += format - spec_start;
1164 g_warning (G_GNUC_PRETTY_FUNCTION
1165 "(): unable to handle `%c' while parsing format",
1169 conv_done |= conv_len > 0;
1172 /* handle width specifications */
1173 conv_len = MAX (conv_len, MAX (spec.precision, spec.min_width));
1175 conv_len += spec.alternate_format ? 2 : 0;
1176 conv_len += (spec.add_space || spec.add_sign || spec.possible_sign);
1179 } /* else (c == '%') */
1180 } /* while (*format) */
1185 #endif /* !HAVE_C99_VSNPRINTF */
1189 g_printf_string_upper_bound (const gchar *format,
1192 #if HAVE_C99_VSNPRINTF
1194 return vsnprintf (&c, 1, format, args) + 1;
1196 return printf_string_upper_bound (format, TRUE, args);
1201 g_messages_init (void)
1203 g_messages_lock = g_mutex_new ();
1204 g_log_depth = g_private_new (NULL);
1205 g_messages_prefixed_init ();
1209 gboolean _g_debug_initialized = FALSE;
1210 guint _g_debug_flags = 0;
1213 _g_debug_init (void)
1217 _g_debug_initialized = TRUE;
1219 val = g_getenv ("G_DEBUG");
1222 static const GDebugKey keys[] = {
1223 {"fatal_warnings", G_DEBUG_FATAL_WARNINGS}
1226 _g_debug_flags = g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
1229 if (_g_debug_flags & G_DEBUG_FATAL_WARNINGS)
1231 GLogLevelFlags fatal_mask;
1233 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
1234 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
1235 g_log_set_always_fatal (fatal_mask);