mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-30 05:43:28 +02:00
Include a printf implementation supporting C99 snprintf and SUS
positional parameters: (#79488) * glib/gstrfuncs.c: * glib/gspawn-win32.c: * glib/gscanner.c: * glib/gconvert.c: * glib/gbacktrace.c: Use _g_printf wrappers. * glib/gutils.c (g_vsnprintf): Simplify, since we can assume C99 snprintf semantics now. * glib/gmessages.c (printf_string_upper_bound): No longer needed, since we can assume C99 snprintf semantics now. (g_logv): Simplify. * acinclude.m4 (AC_FUNC_PRINTF_UNIX98): New macro to check wether printf supports SUS positional parameters. * configure.in: New option --enable-included-printf to force compilation of trio; otherwise trio is compiled if the system printf misses either C99 snprintf semantics of SUS positional parameters. * glib/Makefile.am (SUBDIRS): Conditionally compile trio. (libglib_2_0_la_SOURCES): Add gprintf.c and gprintfint.h. (glibsubinclude_HEADERS): Add gprintf.h. * glib/gprintfint.h: New private wrapping either system printf or trio printf variants in _g_printf wrappers for use inside glib. * glib/gprintf.h: New public header declaring g_printf variants. * glib/gprintf.c: Corresponding implementations. * glib/trio/*: New directory, containing the trio-1.9 sources. * glib/tmpl/string_utils.sgml: Add note on including gprintf.h, move some docs inline. * glib/glib-sections.txt: Add g_printf, g_vprintf, g_fprintf, g_vfprintf, g_sprintf, g_vsprintf.
This commit is contained in:
@@ -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
|
||||
@@ -340,54 +341,6 @@ g_find_program_in_path (const gchar *program)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gint
|
||||
g_snprintf (gchar *str,
|
||||
gulong n,
|
||||
gchar const *fmt,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
gint retval;
|
||||
|
||||
va_start (args, fmt);
|
||||
retval = g_vsnprintf (str, n, fmt, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
gint
|
||||
g_vsnprintf (gchar *str,
|
||||
gulong n,
|
||||
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 */
|
||||
}
|
||||
|
||||
guint
|
||||
g_parse_debug_string (const gchar *string,
|
||||
const GDebugKey *keys,
|
||||
|
Reference in New Issue
Block a user