? trio.diff
Index: acinclude.m4
===================================================================
RCS file: /cvs/gnome/glib/acinclude.m4,v
retrieving revision 1.15
diff -u -b -B -p -r1.15 acinclude.m4
--- acinclude.m4	22 May 2002 19:52:32 -0000	1.15
+++ acinclude.m4	20 Nov 2002 00:02:17 -0000
@@ -327,3 +327,37 @@ if test $ac_cv_func_vsnprintf_c99 = yes;
 fi
 ])# AC_FUNC_VSNPRINTF_C99
 
+
+dnl @synopsis AC_FUNC_PRINTF_UNIX98
+dnl
+dnl Check whether the printf() family supports Unix98 %n$ positional parameters 
+dnl
+AC_DEFUN([AC_FUNC_PRINTF_UNIX98],
+[AC_CACHE_CHECK(whether printf supports positional parameters,
+  ac_cv_func_printf_unix98,
+[AC_TRY_RUN(
+[#include <stdio.h>
+
+int
+main (void)
+{
+  char buffer[128];
+
+  sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
+  if (strcmp ("2 3 1", buffer) == 0)
+    exit (0);
+  exit (1);
+}], ac_cv_func_printf_unix98=yes, ac_cv_func_printf_unix98=no, ac_cv_func_printf_unix98=no)])
+dnl Note that the default is to be pessimistic in the case of cross compilation.
+dnl If you know that the target printf() supports positional parameters, you can get around 
+dnl this by setting ac_func_printf_unix98 to yes, as described in the Autoconf manual.
+if test $ac_cv_func_printf_unix98 = yes; then
+  AC_DEFINE(HAVE_UNIX98_PRINTF, 1,
+            [Define if your printf function family supports positional parameters
+             as specified by Unix98.])
+fi
+])# AC_FUNC_PRINTF_UNIX98
+
+
+
+
Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.305
diff -u -b -B -p -r1.305 configure.in
--- configure.in	8 Nov 2002 00:51:22 -0000	1.305
+++ configure.in	20 Nov 2002 00:02:18 -0000
@@ -380,7 +380,7 @@ esac
 
 dnl Initialize libtool
 AM_DISABLE_STATIC
-AC_LIBTOOL_WIN32_DLL
+cd gAC_LIBTOOL_WIN32_DLL
 AM_PROG_LIBTOOL
 
 if test "x$GCC" = "xyes"; then
@@ -712,6 +712,32 @@ AC_MSG_RESULT(unsigned $glib_size_type)
 AC_CHECK_FUNCS(lstat strerror strsignal memmove mkstemp vsnprintf stpcpy strcasecmp strncasecmp poll getcwd nanosleep vasprintf unsetenv getc_unlocked)
 
 AC_FUNC_VSNPRINTF_C99
+AC_FUNC_PRINTF_UNIX98
+
+#
+# Check whether to use trio printf
+#
+
+AC_ARG_ENABLE(included-printf, [  --enable-included-printf    use included printf [default=auto]], enable_trio="$enableval")
+
+if test "$enable_trio" != "no" ; then
+  if test "$ac_cv_func_vsnprintf_c99" != "yes" ; then
+    enable_trio = yes
+  fi
+  if test "$ac_cv_func_printf_unix98" != "yes" ; then
+    enable_trio = yes
+  fi
+fi
+
+AM_CONDITIONAL(HAVE_GOOD_PRINTF, test "$enable_trio" != "yes")
+if test "$enable_trio" != "yes" ; then 
+  AC_DEFINE(HAVE_GOOD_PRINTF,1,[define to use system printf])
+  AC_DEFINE(HAVE_VASPRINTF,1)
+  AC_DEFINE(HAVE_C99_VSNPRINTF,1)
+  AC_DEFINE(HAVE_UNIX98_PRINTF,1)
+else
+  AC_DEFINE(HAVE_GOOD_PRINTF,0)
+fi
 
 # Check if bcopy can be used for overlapping copies, if memmove isn't found.
 # The check is borrowed from the PERL Configure script.
@@ -2355,6 +2381,7 @@ build/win32/Makefile
 build/win32/dirent/Makefile
 glib/Makefile
 glib/libcharset/Makefile
+glib/trio/Makefile
 gmodule/gmoduleconf.h
 gmodule/Makefile
 gobject/Makefile
Index: glib/Makefile.am
===================================================================
RCS file: /cvs/gnome/glib/glib/Makefile.am,v
retrieving revision 1.101
diff -u -b -B -p -r1.101 Makefile.am
--- glib/Makefile.am	5 Mar 2002 05:17:39 -0000	1.101
+++ glib/Makefile.am	20 Nov 2002 00:02:18 -0000
@@ -1,6 +1,11 @@
 ## Process this file with automake to produce Makefile.in
 
-SUBDIRS=libcharset
+if HAVE_GOOD_PRINTF
+else
+TRIO_SUBDIR = trio
+endif 
+
+SUBDIRS=libcharset $(TRIO_SUBDIR)
 
 INCLUDES = -I$(top_srcdir) -DG_LOG_DOMAIN=\"GLib\" \
 	@GLIB_DEBUG_FLAGS@ -DG_DISABLE_DEPRECATED -DGLIB_COMPILATION 
@@ -82,7 +87,8 @@ libglib_2_0_la_SOURCES = 	\
 	gunidecomp.h		\
 	gunidecomp.c		\
 	gutils.c		\
-	gdebug.h
+	gdebug.h		\
+	gprintfint.h
 
 EXTRA_libglib_2_0_la_SOURCES = \
 	giounix.c	\
Index: glib/gbacktrace.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gbacktrace.c,v
retrieving revision 1.16
diff -u -b -B -p -r1.16 gbacktrace.c
--- glib/gbacktrace.c	9 Mar 2001 21:18:33 -0000	1.16
+++ glib/gbacktrace.c	20 Nov 2002 00:02:18 -0000
@@ -38,6 +38,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "glib.h"
+#include "gprintfint.h"
+
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
@@ -98,7 +100,7 @@ g_on_error_query (const gchar *prg_name)
  retry:
   
   if (prg_name)
-    fprintf (stdout,
+    _g_fprintf (stdout,
 	     "%s (pid:%u): %s%s%s: ",
 	     prg_name,
 	     (guint) getpid (),
@@ -106,7 +108,7 @@ g_on_error_query (const gchar *prg_name)
 	     query2,
 	     query3);
   else
-    fprintf (stdout,
+    _g_fprintf (stdout,
 	     "(process:%u): %s%s: ",
 	     (guint) getpid (),
 	     query1,
@@ -163,7 +165,7 @@ g_on_error_stack_trace (const gchar *prg
   if (!prg_name)
     return;
 
-  sprintf (buf, "%u", (guint) getpid ());
+  _g_sprintf (buf, "%u", (guint) getpid ());
 
   args[1] = (gchar*) prg_name;
   args[2] = buf;
@@ -276,7 +278,7 @@ stack_trace (char **args)
                   if ((c == '\n') || (c == '\r'))
                     {
                       buffer[index] = 0;
-                      fprintf (stdout, "%s", buffer);
+                      _g_fprintf (stdout, "%s", buffer);
                       state = 0;
                       index = 0;
                     }
Index: glib/gconvert.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gconvert.c,v
retrieving revision 1.41
diff -u -b -B -p -r1.41 gconvert.c
--- glib/gconvert.c	20 Aug 2002 23:03:17 -0000	1.41
+++ glib/gconvert.c	20 Nov 2002 00:02:19 -0000
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 
 #include "glib.h"
+#include "gprintfint.h"
 
 #ifdef G_PLATFORM_WIN32
 #define STRICT
@@ -338,7 +339,7 @@ open_converter (const gchar *to_codeset,
   
   /* create our key */
   key = g_alloca (strlen (from_codeset) + strlen (to_codeset) + 2);
-  sprintf (key, "%s:%s", from_codeset, to_codeset);
+  _g_sprintf (key, "%s:%s", from_codeset, to_codeset);
   
   G_LOCK (iconv_cache_lock);
   
Index: glib/gmessages.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gmessages.c,v
retrieving revision 1.48
diff -u -b -B -p -r1.48 gmessages.c
--- glib/gmessages.c	13 May 2002 15:51:42 -0000	1.48
+++ glib/gmessages.c	20 Nov 2002 00:02:19 -0000
@@ -44,6 +44,7 @@
 #include <locale.h>
 #include <errno.h>
 #include "gdebug.h"
+#include "gprintfint.h"
 
 #ifdef G_OS_WIN32
 typedef FILE* GFileDescriptor;
@@ -71,14 +72,6 @@ struct _GLogHandler
 };
 
 
-/* --- prototypes --- */
-#ifndef HAVE_C99_VSNPRINTF
-static gsize printf_string_upper_bound (const gchar *format,
-					gboolean     may_warn,
-					va_list      args);
-#endif /* !HAVE_C99_VSNPRINTF */
-
-
 /* --- variables --- */
 static GMutex        *g_messages_lock = NULL;
 static GLogDomain    *g_log_domains = NULL;
@@ -409,10 +402,6 @@ g_logv (const gchar   *log_domain,
   gboolean was_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0;
   gint i;
 
-#ifndef  HAVE_VSNPRINTF
-  va_list args2;
-#endif	/* HAVE_VSNPRINTF */
-  
   log_level &= G_LOG_LEVEL_MASK;
   if (!log_level)
     return;
@@ -420,21 +409,7 @@ g_logv (const gchar   *log_domain,
   /* we use a stack buffer of fixed size, because we might get called
    * recursively.
    */
-#ifdef  HAVE_VSNPRINTF
-  vsnprintf (buffer, 1024, format, args1);
-#else	/* !HAVE_VSNPRINTF */
-  G_VA_COPY (args2, args1);
-  if (printf_string_upper_bound (format, FALSE, args1) < 1024)
-    vsprintf (buffer, format, args2);
-  else
-    {
-      /* since we might be out of memory, we can't use g_vsnprintf(). */
-      /* we are out of luck here */
-      strncpy (buffer, format, 1024);
-      buffer[1024] = 0;
-    }
-  va_end (args2);
-#endif	/* !HAVE_VSNPRINTF */
+  _g_vsnprintf (buffer, 1024, format, args1);
   
   for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i))
     {
@@ -548,7 +523,7 @@ strdup_convert (const gchar *string,
 	  if (!warned)
 	    {
 	      warned = TRUE;
-	      fprintf (stderr, "GLib: Cannot convert message: %s\n", err->message);
+	      _g_fprintf (stderr, "GLib: Cannot convert message: %s\n", err->message);
 	    }
 	  g_error_free (err);
 	  
@@ -909,333 +884,12 @@ g_printerr (const gchar *format,
   g_free (string);
 }
 
-#ifndef MB_LEN_MAX
-#  define MB_LEN_MAX 8
-#endif
-
-#ifndef HAVE_C99_VSNPRINTF
-
-typedef struct
-{
-  guint min_width;
-  guint precision;
-  gboolean alternate_format, zero_padding, adjust_left, locale_grouping;
-  gboolean add_space, add_sign, possible_sign, seen_precision;
-  gboolean mod_half, mod_long, mod_extra_long;
-} PrintfArgSpec;
-
-static gsize
-printf_string_upper_bound (const gchar *format,
-			   gboolean     may_warn,
-			   va_list      args)
-{
-  static const gboolean honour_longs = SIZEOF_LONG > 4 || SIZEOF_VOID_P > 4;
-  gsize len = 1;
-  
-  if (!format)
-    return len;
-  
-  while (*format)
-    {
-      register gchar c = *format++;
-      
-      if (c != '%')
-	len += 1;
-      else /* (c == '%') */
-	{
-	  PrintfArgSpec spec = { 0, };
-	  gboolean seen_l = FALSE, conv_done = FALSE;
-	  gsize conv_len = 0;
-	  const gchar *spec_start = format;
-	  
-	  do
-	    {
-	      c = *format++;
-	      switch (c)
-		{
-		  GDoubleIEEE754 u_double;
-		  guint v_uint;
-		  gint v_int;
-		  const gchar *v_string;
-		  
-		  /* beware of positional parameters
-		   */
-		case '$':
-		  if (may_warn)
-		    g_warning (G_GNUC_PRETTY_FUNCTION
-			       "(): unable to handle positional parameters (%%n$)");
-		  len += 1024; /* try adding some safety padding */
-		  conv_done = TRUE;
-		  break;
-		  
-		  /* parse flags
-		   */
-		case '#':
-		  spec.alternate_format = TRUE;
-		  break;
-		case '0':
-		  spec.zero_padding = TRUE;
-		  break;
-		case '-':
-		  spec.adjust_left = TRUE;
-		  break;
-		case ' ':
-		  spec.add_space = TRUE;
-		  break;
-		case '+':
-		  spec.add_sign = TRUE;
-		  break;
-		case '\'':
-		  spec.locale_grouping = TRUE;
-		  break;
-		  
-		  /* parse output size specifications
-		   */
-		case '.':
-		  spec.seen_precision = TRUE;
-		  break;
-		case '1':
-		case '2':
-		case '3':
-		case '4':
-		case '5':
-		case '6':
-		case '7':
-		case '8':
-		case '9':
-		  v_uint = c - '0';
-		  c = *format;
-		  while (c >= '0' && c <= '9')
-		    {
-		      format++;
-		      v_uint = v_uint * 10 + c - '0';
-		      c = *format;
-		    }
-		  if (spec.seen_precision)
-		    spec.precision = MAX (spec.precision, v_uint);
-		  else
-		    spec.min_width = MAX (spec.min_width, v_uint);
-		  break;
-		case '*':
-		  v_int = va_arg (args, int);
-		  if (spec.seen_precision)
-		    {
-		      /* forget about negative precision */
-		      if (v_int >= 0)
-			spec.precision = MAX (spec.precision, v_int);
-		    }
-		  else
-		    {
-		      if (v_int < 0)
-			{
-			  v_int = - v_int;
-			  spec.adjust_left = TRUE;
-			}
-		      spec.min_width = MAX (spec.min_width, v_int);
-		    }
-		  break;
-		  
-		  /* parse type modifiers
-		   */
-		case 'h':
-		  spec.mod_half = TRUE;
-		  break;
-		case 'l':
-		  if (!seen_l)
-		    {
-		      spec.mod_long = TRUE;
-		      seen_l = TRUE;
-		      break;
-		    }
-		  /* else, fall through */
-		case 'L':
-		case 'q':
-		  spec.mod_long = TRUE;
-		  spec.mod_extra_long = TRUE;
-		  break;
-		case 'z':
-		case 'Z':
-#if GLIB_SIZEOF_SIZE_T > 4
-		  spec.mod_long = TRUE;
-		  spec.mod_extra_long = TRUE;
-#endif /* GLIB_SIZEOF_SIZE_T > 4 */
-		  break;
-		case 't':
-#if GLIB_SIZEOF_PTRDIFF_T > 4
-		  spec.mod_long = TRUE;
-		  spec.mod_extra_long = TRUE;
-#endif /* GLIB_SIZEOF_PTRDIFF_T > 4 */
-		  break;
-		case 'j':
-#if GLIB_SIZEOF_INTMAX_T > 4
-		  spec.mod_long = TRUE;
-		  spec.mod_extra_long = TRUE;
-#endif /* GLIB_SIZEOF_INTMAX_T > 4 */
-		  break;
-		  
-		  /* parse output conversions
-		   */
-		case '%':
-		  conv_len += 1;
-		  break;
-		case 'O':
-		case 'D':
-		case 'I':
-		case 'U':
-		  /* some C libraries feature long variants for these as well? */
-		  spec.mod_long = TRUE;
-		  /* fall through */
-		case 'o':
-		  conv_len += 2;
-		  /* fall through */
-		case 'd':
-		case 'i':
-		  conv_len += 1; /* sign */
-		  /* fall through */
-		case 'u':
-		  conv_len += 4;
-		  /* fall through */
-		case 'x':
-		case 'X':
-		  spec.possible_sign = TRUE;
-		  conv_len += 10;
-		  if (spec.mod_long && honour_longs)
-		    conv_len *= 2;
-		  if (spec.mod_extra_long)
-		    conv_len *= 2;
-		  if (spec.mod_extra_long)
-		    {
-		      (void) va_arg (args, gint64);
-		    }
-		  else if (spec.mod_long)
-		    (void) va_arg (args, long);
-		  else
-		    (void) va_arg (args, int);
-		  break;
-		case 'A':
-		case 'a':
-		  /*          0x */
-		  conv_len += 2;
-		  /* fall through */
-		case 'g':
-		case 'G':
-		case 'e':
-		case 'E':
-		case 'f':
-		  spec.possible_sign = TRUE;
-		  /*          n   .   dddddddddddddddddddddddd   E   +-  eeee */
-		  conv_len += 1 + 1 + MAX (24, spec.precision) + 1 + 1 + 4;
-                  if (may_warn && spec.mod_extra_long)
-		    g_warning (G_GNUC_PRETTY_FUNCTION
-			       "(): unable to handle long double, collecting double only");
-#ifdef HAVE_LONG_DOUBLE
-#error need to implement special handling for long double
-#endif
-		  u_double.v_double = va_arg (args, double);
-		  /* %f can expand up to all significant digits before '.' (308) */
-		  if (c == 'f' &&
-		      u_double.mpn.biased_exponent > 0 && u_double.mpn.biased_exponent < 2047)
-		    {
-		      gint exp = u_double.mpn.biased_exponent;
-		      
-		      exp -= G_IEEE754_DOUBLE_BIAS;
-		      exp = exp * G_LOG_2_BASE_10 + 1;
-		      conv_len += ABS (exp);	/* exp can be <0 */
-		    }
-		  /* some printf() implementations require extra padding for rounding */
-		  conv_len += 2;
-		  /* we can't really handle locale specific grouping here */
-		  if (spec.locale_grouping)
-		    conv_len *= 2;
-		  break;
-		case 'C':
-		  spec.mod_long = TRUE;
-                  /* fall through */
-		case 'c':
-		  conv_len += spec.mod_long ? MB_LEN_MAX : 1;
-		  (void) va_arg (args, int);
-		  break;
-		case 'S':
-		  spec.mod_long = TRUE;
-		  /* fall through */
-		case 's':
-		  v_string = va_arg (args, char*);
-		  if (!v_string)
-		    conv_len += 8; /* hold "(null)" */
-		  else if (spec.seen_precision)
-		    conv_len += spec.precision;
-		  else
-		    conv_len += strlen (v_string);
-		  conv_done = TRUE;
-		  if (spec.mod_long)
-		    {
-		      if (may_warn)
-			g_warning (G_GNUC_PRETTY_FUNCTION
-				   "(): unable to handle wide char strings");
-		      len += 1024; /* try adding some safety padding */
-		    }
-		  break;
-		case 'P': /* do we actually need this? */
-		  /* fall through */
-		case 'p':
-		  spec.alternate_format = TRUE;
-		  conv_len += 10;
-		  if (honour_longs)
-		    conv_len *= 2;
-		  /* fall through */
-		case 'n':
-		  conv_done = TRUE;
-		  (void) va_arg (args, void*);
-		  break;
-		case 'm':
-		  /* there's not much we can do to be clever */
-		  v_string = g_strerror (errno);
-		  v_uint = v_string ? strlen (v_string) : 0;
-		  conv_len += MAX (256, v_uint);
-		  break;
-		  
-		  /* handle invalid cases
-		   */
-		case '\000':
-		  /* no conversion specification, bad bad */
-		  conv_len += format - spec_start;
-		  break;
-		default:
-		  if (may_warn)
-		    g_warning (G_GNUC_PRETTY_FUNCTION
-			       "(): unable to handle `%c' while parsing format",
-			       c);
-		  break;
-		}
-	      conv_done |= conv_len > 0;
-	    }
-	  while (!conv_done);
-	  /* handle width specifications */
-	  conv_len = MAX (conv_len, MAX (spec.precision, spec.min_width));
-	  /* handle flags */
-	  conv_len += spec.alternate_format ? 2 : 0;
-	  conv_len += (spec.add_space || spec.add_sign || spec.possible_sign);
-	  /* finally done */
-	  len += conv_len;
-	} /* else (c == '%') */
-    } /* while (*format) */
-  
-  return len;
-}
-
-#endif /* !HAVE_C99_VSNPRINTF */
-
-
 gsize
 g_printf_string_upper_bound (const gchar *format,
 			     va_list      args)
 {
-#if HAVE_C99_VSNPRINTF
   gchar c;
-  return vsnprintf (&c, 1, format, args) + 1;
-#else
-  return printf_string_upper_bound (format, TRUE, args);
-#endif
+  return _g_vsnprintf (&c, 1, format, args) + 1;
 }
 
 void
Index: glib/gscanner.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gscanner.c,v
retrieving revision 1.43
diff -u -b -B -p -r1.43 gscanner.c
--- glib/gscanner.c	12 Oct 2002 19:37:48 -0000	1.43
+++ glib/gscanner.c	20 Nov 2002 00:02:20 -0000
@@ -40,6 +40,7 @@
 #include	<string.h>
 #include	<stdio.h>
 #include	"glib.h"
+#include	"gprintfint.h"
 #ifdef HAVE_UNISTD_H
 #include	<unistd.h>
 #endif
@@ -290,12 +291,12 @@ g_scanner_msg_handler (GScanner		*scanne
 {
   g_return_if_fail (scanner != NULL);
   
-  fprintf (stderr, "%s:%d: ",
+  _g_fprintf (stderr, "%s:%d: ",
 	   scanner->input_name ? scanner->input_name : "<memory>",
 	   scanner->line);
   if (is_error)
-    fprintf (stderr, "error: ");
-  fprintf (stderr, "%s\n", message);
+    _g_fprintf (stderr, "error: ");
+  _g_fprintf (stderr, "%s\n", message);
 }
 
 void
@@ -856,7 +857,7 @@ g_scanner_unexp_token (GScanner		*scanne
   switch (scanner->token)
     {
     case G_TOKEN_EOF:
-      g_snprintf (token_string, token_string_len, "end of file");
+      _g_snprintf (token_string, token_string_len, "end of file");
       break;
       
     default:
@@ -865,14 +866,14 @@ g_scanner_unexp_token (GScanner		*scanne
 	  if ((scanner->token >= ' ' && scanner->token <= '~') ||
 	      strchr (scanner->config->cset_identifier_first, scanner->token) ||
 	      strchr (scanner->config->cset_identifier_nth, scanner->token))
-	    g_snprintf (token_string, token_string_len, "character `%c'", scanner->token);
+	    _g_snprintf (token_string, token_string_len, "character `%c'", scanner->token);
 	  else
-	    g_snprintf (token_string, token_string_len, "character `\\%o'", scanner->token);
+	    _g_snprintf (token_string, token_string_len, "character `\\%o'", scanner->token);
 	  break;
 	}
       else if (!scanner->config->symbol_2_token)
 	{
-	  g_snprintf (token_string, token_string_len, "(unknown) token <%d>", scanner->token);
+	  _g_snprintf (token_string, token_string_len, "(unknown) token <%d>", scanner->token);
 	  break;
 	}
       /* fall through */
@@ -882,14 +883,14 @@ g_scanner_unexp_token (GScanner		*scanne
 	   expected_token > G_TOKEN_LAST))
 	print_unexp = FALSE;
       if (symbol_name)
-	g_snprintf (token_string,
+	_g_snprintf (token_string,
 		    token_string_len,
 		    "%s%s `%s'",
 		    print_unexp ? "" : "invalid ",
 		    symbol_spec,
 		    symbol_name);
       else
-	g_snprintf (token_string,
+	_g_snprintf (token_string,
 		    token_string_len,
 		    "%s%s",
 		    print_unexp ? "" : "invalid ",
@@ -902,42 +903,42 @@ g_scanner_unexp_token (GScanner		*scanne
       switch (scanner->value.v_error)
 	{
 	case G_ERR_UNEXP_EOF:
-	  g_snprintf (token_string, token_string_len, "scanner: unexpected end of file");
+	  _g_snprintf (token_string, token_string_len, "scanner: unexpected end of file");
 	  break;
 	  
 	case G_ERR_UNEXP_EOF_IN_STRING:
-	  g_snprintf (token_string, token_string_len, "scanner: unterminated string constant");
+	  _g_snprintf (token_string, token_string_len, "scanner: unterminated string constant");
 	  break;
 	  
 	case G_ERR_UNEXP_EOF_IN_COMMENT:
-	  g_snprintf (token_string, token_string_len, "scanner: unterminated comment");
+	  _g_snprintf (token_string, token_string_len, "scanner: unterminated comment");
 	  break;
 	  
 	case G_ERR_NON_DIGIT_IN_CONST:
-	  g_snprintf (token_string, token_string_len, "scanner: non digit in constant");
+	  _g_snprintf (token_string, token_string_len, "scanner: non digit in constant");
 	  break;
 	  
 	case G_ERR_FLOAT_RADIX:
-	  g_snprintf (token_string, token_string_len, "scanner: invalid radix for floating constant");
+	  _g_snprintf (token_string, token_string_len, "scanner: invalid radix for floating constant");
 	  break;
 	  
 	case G_ERR_FLOAT_MALFORMED:
-	  g_snprintf (token_string, token_string_len, "scanner: malformed floating constant");
+	  _g_snprintf (token_string, token_string_len, "scanner: malformed floating constant");
 	  break;
 	  
 	case G_ERR_DIGIT_RADIX:
-	  g_snprintf (token_string, token_string_len, "scanner: digit is beyond radix");
+	  _g_snprintf (token_string, token_string_len, "scanner: digit is beyond radix");
 	  break;
 	  
 	case G_ERR_UNKNOWN:
 	default:
-	  g_snprintf (token_string, token_string_len, "scanner: unknown error");
+	  _g_snprintf (token_string, token_string_len, "scanner: unknown error");
 	  break;
 	}
       break;
       
     case G_TOKEN_CHAR:
-      g_snprintf (token_string, token_string_len, "character `%c'", scanner->value.v_char);
+      _g_snprintf (token_string, token_string_len, "character `%c'", scanner->value.v_char);
       break;
       
     case G_TOKEN_IDENTIFIER:
@@ -945,7 +946,7 @@ g_scanner_unexp_token (GScanner		*scanne
       if (expected_token == G_TOKEN_IDENTIFIER ||
 	  expected_token == G_TOKEN_IDENTIFIER_NULL)
 	print_unexp = FALSE;
-      g_snprintf (token_string,
+      _g_snprintf (token_string,
 		  token_string_len,
 		  "%s%s `%s'",
 		  print_unexp ? "" : "invalid ",
@@ -958,19 +959,19 @@ g_scanner_unexp_token (GScanner		*scanne
     case G_TOKEN_INT:
     case G_TOKEN_HEX:
       if (scanner->config->store_int64)
-	g_snprintf (token_string, token_string_len, "number `%llu'", scanner->value.v_int64);
+	_g_snprintf (token_string, token_string_len, "number `%llu'", scanner->value.v_int64);
       else
-	g_snprintf (token_string, token_string_len, "number `%lu'", scanner->value.v_int);
+	_g_snprintf (token_string, token_string_len, "number `%lu'", scanner->value.v_int);
       break;
       
     case G_TOKEN_FLOAT:
-      g_snprintf (token_string, token_string_len, "number `%.3f'", scanner->value.v_float);
+      _g_snprintf (token_string, token_string_len, "number `%.3f'", scanner->value.v_float);
       break;
       
     case G_TOKEN_STRING:
       if (expected_token == G_TOKEN_STRING)
 	print_unexp = FALSE;
-      g_snprintf (token_string,
+      _g_snprintf (token_string,
 		  token_string_len,
 		  "%s%sstring constant \"%s\"",
 		  print_unexp ? "" : "invalid ",
@@ -982,7 +983,7 @@ g_scanner_unexp_token (GScanner		*scanne
       
     case G_TOKEN_COMMENT_SINGLE:
     case G_TOKEN_COMMENT_MULTI:
-      g_snprintf (token_string, token_string_len, "comment");
+      _g_snprintf (token_string, token_string_len, "comment");
       break;
       
     case G_TOKEN_NONE:
@@ -1002,7 +1003,7 @@ g_scanner_unexp_token (GScanner		*scanne
       gboolean need_valid;
       gchar *tstring;
     case G_TOKEN_EOF:
-      g_snprintf (expected_string, expected_string_len, "end of file");
+      _g_snprintf (expected_string, expected_string_len, "end of file");
       break;
     default:
       if (expected_token >= 1 && expected_token <= 255)
@@ -1010,14 +1011,14 @@ g_scanner_unexp_token (GScanner		*scanne
 	  if ((expected_token >= ' ' && expected_token <= '~') ||
 	      strchr (scanner->config->cset_identifier_first, expected_token) ||
 	      strchr (scanner->config->cset_identifier_nth, expected_token))
-	    g_snprintf (expected_string, expected_string_len, "character `%c'", expected_token);
+	    _g_snprintf (expected_string, expected_string_len, "character `%c'", expected_token);
 	  else
-	    g_snprintf (expected_string, expected_string_len, "character `\\%o'", expected_token);
+	    _g_snprintf (expected_string, expected_string_len, "character `\\%o'", expected_token);
 	  break;
 	}
       else if (!scanner->config->symbol_2_token)
 	{
-	  g_snprintf (expected_string, expected_string_len, "(unknown) token <%d>", expected_token);
+	  _g_snprintf (expected_string, expected_string_len, "(unknown) token <%d>", expected_token);
 	  break;
 	}
       /* fall through */
@@ -1025,7 +1026,7 @@ g_scanner_unexp_token (GScanner		*scanne
       need_valid = (scanner->token == G_TOKEN_SYMBOL ||
 		    (scanner->config->symbol_2_token &&
 		     scanner->token > G_TOKEN_LAST));
-      g_snprintf (expected_string,
+      _g_snprintf (expected_string,
 		  expected_string_len,
 		  "%s%s",
 		  need_valid ? "valid " : "",
@@ -1033,36 +1034,36 @@ g_scanner_unexp_token (GScanner		*scanne
       /* FIXME: should we attempt to lookup the symbol_name for symbol_2_token? */
       break;
     case G_TOKEN_CHAR:
-      g_snprintf (expected_string, expected_string_len, "%scharacter",
+      _g_snprintf (expected_string, expected_string_len, "%scharacter",
 		  scanner->token == G_TOKEN_CHAR ? "valid " : "");
       break;
     case G_TOKEN_BINARY:
       tstring = "binary";
-      g_snprintf (expected_string, expected_string_len, "%snumber (%s)",
+      _g_snprintf (expected_string, expected_string_len, "%snumber (%s)",
 		  scanner->token == expected_token ? "valid " : "", tstring);
       break;
     case G_TOKEN_OCTAL:
       tstring = "octal";
-      g_snprintf (expected_string, expected_string_len, "%snumber (%s)",
+      _g_snprintf (expected_string, expected_string_len, "%snumber (%s)",
 		  scanner->token == expected_token ? "valid " : "", tstring);
       break;
     case G_TOKEN_INT:
       tstring = "integer";
-      g_snprintf (expected_string, expected_string_len, "%snumber (%s)",
+      _g_snprintf (expected_string, expected_string_len, "%snumber (%s)",
 		  scanner->token == expected_token ? "valid " : "", tstring);
       break;
     case G_TOKEN_HEX:
       tstring = "hexadecimal";
-      g_snprintf (expected_string, expected_string_len, "%snumber (%s)",
+      _g_snprintf (expected_string, expected_string_len, "%snumber (%s)",
 		  scanner->token == expected_token ? "valid " : "", tstring);
       break;
     case G_TOKEN_FLOAT:
       tstring = "float";
-      g_snprintf (expected_string, expected_string_len, "%snumber (%s)",
+      _g_snprintf (expected_string, expected_string_len, "%snumber (%s)",
 		  scanner->token == expected_token ? "valid " : "", tstring);
       break;
     case G_TOKEN_STRING:
-      g_snprintf (expected_string,
+      _g_snprintf (expected_string,
 		  expected_string_len,
 		  "%sstring constant",
 		  scanner->token == G_TOKEN_STRING ? "valid " : "");
@@ -1071,7 +1072,7 @@ g_scanner_unexp_token (GScanner		*scanne
     case G_TOKEN_IDENTIFIER_NULL:
       need_valid = (scanner->token == G_TOKEN_IDENTIFIER_NULL ||
 		    scanner->token == G_TOKEN_IDENTIFIER);
-      g_snprintf (expected_string,
+      _g_snprintf (expected_string,
 		  expected_string_len,
 		  "%s%s",
 		  need_valid ? "valid " : "",
@@ -1079,12 +1080,12 @@ g_scanner_unexp_token (GScanner		*scanne
       break;
     case G_TOKEN_COMMENT_SINGLE:
       tstring = "single-line";
-      g_snprintf (expected_string, expected_string_len, "%scomment (%s)",
+      _g_snprintf (expected_string, expected_string_len, "%scomment (%s)",
 		  scanner->token == expected_token ? "valid " : "", tstring);
       break;
     case G_TOKEN_COMMENT_MULTI:
       tstring = "multi-line";
-      g_snprintf (expected_string, expected_string_len, "%scomment (%s)",
+      _g_snprintf (expected_string, expected_string_len, "%scomment (%s)",
 		  scanner->token == expected_token ? "valid " : "", tstring);
       break;
     case G_TOKEN_NONE:
Index: glib/gspawn-win32.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gspawn-win32.c,v
retrieving revision 1.16
diff -u -b -B -p -r1.16 gspawn-win32.c
--- glib/gspawn-win32.c	18 Nov 2002 09:58:39 -0000	1.16
+++ glib/gspawn-win32.c	20 Nov 2002 00:02:20 -0000
@@ -40,6 +40,7 @@
 #include <config.h>
 
 #include "glib.h"
+#include "gprintfint.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -555,12 +556,12 @@ do_spawn (gboolean              dont_wai
   new_argv = g_new (gchar *, argc + 1 + ARG_COUNT);
 
   new_argv[0] = "gspawn-win32-helper";
-  sprintf (args[ARG_CHILD_ERR_REPORT], "%d", child_err_report_fd);
+  _g_sprintf (args[ARG_CHILD_ERR_REPORT], "%d", child_err_report_fd);
   new_argv[ARG_CHILD_ERR_REPORT] = args[ARG_CHILD_ERR_REPORT];
 
   if (stdin_fd >= 0)
     {
-      sprintf (args[ARG_STDIN], "%d", stdin_fd);
+      _g_sprintf (args[ARG_STDIN], "%d", stdin_fd);
       new_argv[ARG_STDIN] = args[ARG_STDIN];
     }
   else if (child_inherits_stdin)
@@ -576,7 +577,7 @@ do_spawn (gboolean              dont_wai
 
   if (stdout_fd >= 0)
     {
-      sprintf (args[ARG_STDOUT], "%d", stdout_fd);
+      _g_sprintf (args[ARG_STDOUT], "%d", stdout_fd);
       new_argv[ARG_STDOUT] = args[ARG_STDOUT];
     }
   else if (stdout_to_null)
@@ -590,7 +591,7 @@ do_spawn (gboolean              dont_wai
 
   if (stderr_fd >= 0)
     {
-      sprintf (args[ARG_STDERR], "%d", stderr_fd);
+      _g_sprintf (args[ARG_STDERR], "%d", stderr_fd);
       new_argv[ARG_STDERR] = args[ARG_STDERR];
     }
   else if (stderr_to_null)
Index: glib/gstrfuncs.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gstrfuncs.c,v
retrieving revision 1.86
diff -u -b -B -p -r1.86 gstrfuncs.c
--- glib/gstrfuncs.c	19 Nov 2002 19:42:05 -0000	1.86
+++ glib/gstrfuncs.c	20 Nov 2002 00:02:21 -0000
@@ -45,6 +45,7 @@
 #include <signal.h>
 #endif
 #include "glib.h"
+#include "gprintfint.h"
 
 #ifdef G_OS_WIN32
 #include <windows.h>
@@ -183,7 +184,7 @@ g_strdup_vprintf (const gchar *format,
 {
   gchar *buffer;
 #ifdef HAVE_VASPRINTF
-  if (vasprintf (&buffer, format, args1) < 0)
+  if (_g_vasprintf (&buffer, format, args1) < 0)
     buffer = NULL;
   else if (!g_mem_is_system_malloc ()) 
     {
@@ -198,7 +199,7 @@ g_strdup_vprintf (const gchar *format,
 
   buffer = g_new (gchar, g_printf_string_upper_bound (format, args1));
 
-  vsprintf (buffer, format, args2);
+  _g_vsprintf (buffer, format, args2);
   va_end (args2);
 #endif
   return buffer;
@@ -544,7 +545,7 @@ g_ascii_formatd (gchar       *buffer,
     return NULL;
 
       
-  g_snprintf (buffer, buf_len, format, d);
+  _g_snprintf (buffer, buf_len, format, d);
 
   locale_data = localeconv ();
   decimal_point = locale_data->decimal_point;
@@ -1187,7 +1188,7 @@ g_strerror (gint errnum)
       g_static_private_set (&msg_private, msg, g_free);
     }
 
-  sprintf (msg, "unknown error (%d)", errnum);
+  _g_sprintf (msg, "unknown error (%d)", errnum);
 
   return msg;
 }
@@ -1336,7 +1337,7 @@ extern const char *strsignal(int);
       g_static_private_set (&msg_private, msg, g_free);
     }
 
-  sprintf (msg, "unknown signal (%d)", signum);
+  _g_sprintf (msg, "unknown signal (%d)", signum);
   
   return msg;
 }
Index: glib/gutils.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gutils.c,v
retrieving revision 1.110
diff -u -b -B -p -r1.110 gutils.c
--- glib/gutils.c	8 Nov 2002 00:51:25 -0000	1.110
+++ glib/gutils.c	20 Nov 2002 00:02:21 -0000
@@ -53,6 +53,7 @@
 #define	G_IMPLEMENT_INLINES 1
 #define	__G_UTILS_C__
 #include "glib.h"
+#include "gprintfint.h"
 
 #ifdef	MAXPATHLEN
 #define	G_PATH_LENGTH	MAXPATHLEN
@@ -362,30 +363,10 @@ g_vsnprintf (gchar	 *str,
 	     gchar const *fmt,
 	     va_list      args)
 {
-#ifdef	HAVE_VSNPRINTF_C99
   g_return_val_if_fail (n == 0 || str != NULL, 0);
   g_return_val_if_fail (fmt != NULL, 0);
 
-  return vsnprintf (str, n, fmt, args);
-#else	/* !HAVE_VSNPRINTF_C99 */
-  gchar *printed;
-  gint retval;
-
-  g_return_val_if_fail (n == 0 || str != NULL, 0);
-  g_return_val_if_fail (fmt != NULL, 0);
-
-  printed = g_strdup_vprintf (fmt, args);
-  retval = strlen (printed);
-  if (n > 0)
-    {
-      strncpy (str, printed, n - 1);
-      str[n-1] = '\0';
-    }
-
-  g_free (printed);
-  
-  return retval;
-#endif /* !HAVE_VSNPRINTF_C99 */
+  return _g_vsnprintf (str, n, fmt, args);
 }
 
 guint	     
