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:
Matthias Clasen
2002-11-21 00:35:15 +00:00
parent dc645ce354
commit bc54ea6edf
33 changed files with 11455 additions and 561 deletions

View File

@@ -1,3 +1,11 @@
2002-11-21 Matthias Clasen <maclas@gmx.de>
* 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.
2002-11-20 Matthias Clasen <maclas@gmx.de>
* glib/tmpl/macros_misc.sgml: Document G_LIKELY, G_UNLIKELY.

View File

@@ -896,6 +896,12 @@ g_strlcat
<SUBSECTION>
g_strdup_printf
g_strdup_vprintf
g_printf
g_vprintf
g_fprintf
g_vfprintf
g_sprintf
g_vsprintf
g_snprintf
g_vsnprintf
g_printf_string_upper_bound

View File

@@ -9,6 +9,15 @@ various string-related functions.
This section describes a number of utility functions for creating,
duplicating, and manipulating strings.
</para>
<para>
Note that the functions g_printf(), g_fprintf(), g_sprintf(), g_snprintf(),
g_vprintf(), g_vfprintf(), g_vsprintf() and g_vsnprintf() are declared in
the header <filename>gprintf.h</filename> which is <emphasis>not</emphasis>
included in <filename>glib.h</filename> (otherwise using
<filename>glib.h</filename> would drag in <filename>stdio.h</filename>), so
you'll have to explicitly include <literal>&lt;glib/gprintf.h&gt;</literal>
in order to use the printf() functions.
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
@@ -180,78 +189,90 @@ The returned string should be freed when no longer needed.
@Returns: a newly-allocated string holding the result.
<!-- ##### FUNCTION g_printf ##### -->
<para>
</para>
@format:
@Varargs:
@Returns:
<!-- ##### FUNCTION g_vprintf ##### -->
<para>
</para>
@format:
@args:
@Returns:
<!-- ##### FUNCTION g_fprintf ##### -->
<para>
</para>
@file:
@format:
@Varargs:
@Returns:
<!-- ##### FUNCTION g_vfprintf ##### -->
<para>
</para>
@file:
@format:
@args:
@Returns:
<!-- ##### FUNCTION g_sprintf ##### -->
<para>
</para>
@string:
@format:
@Varargs:
@Returns:
<!-- ##### FUNCTION g_vsprintf ##### -->
<para>
</para>
@string:
@format:
@args:
@Returns:
<!-- ##### FUNCTION g_snprintf ##### -->
<para>
A safer form of the standard <function>sprintf()</function> function.
The output is guaranteed to not exceed @n characters (including the
terminating nul character), so it is easy to ensure that a buffer overflow
cannot occur.
</para>
<para>
See also g_strdup_printf().
</para>
<note>
<para>
In versions of GLib prior to 1.2.3, this function may return -1 if the output
was truncated, and the truncated string may not be nul-terminated.
In versions prior to 1.3.12, this function returns the length of the output
string.
</para>
</note>
<note>
<para>
The return value of g_snprintf() conforms to the <function>snprintf()</function>
function as standardized in ISO C99. Note that this is different from
traditional <function>snprintf()</function>, which returns the length of
the output string.
</para>
</note>
@string: the buffer to hold the output.
@n: the maximum number of characters to produce (including the terminating nul
character).
@format: the format string. See the <function>sprintf()</function>.
documentation.
@Varargs: the arguments to insert in the output.
@Returns: the number of characters which would be produced if the buffer was
large enough.
@string:
@n:
@format:
@Varargs:
@Returns:
<!-- ##### FUNCTION g_vsnprintf ##### -->
<para>
A safer form of the standard <function>vsprintf()</function> function.
The output is guaranteed to not exceed @n characters (including the
terminating nul character), so it is easy to ensure that a buffer overflow
cannot occur.
</para>
<para>
See also g_strdup_vprintf().
</para>
<note>
<para>
In versions of GLib prior to 1.2.3, this function may return -1 if the output
was truncated, and the truncated string may not be nul-terminated.
In versions prior to 1.3.12, this function returns the length of the output
string.
</para>
</note>
<note>
<para>
The return value of g_vsnprintf() conforms to the <function>vsnprintf()</function>
function as standardized in ISO C99. Note that this is different from
traditional <function>vsnprintf()</function>, which returns the length of
the output string.
</para>
</note>
@string: the buffer to hold the output.
@n: the maximum number of characters to produce (including the terminating nul
character).
@format: the format string. See the <function>sprintf()</function>
documentation.
@args: the list of arguments to insert in the output.
@Returns: the number of characters which would be produced if the buffer was
large enough.
@string:
@n:
@format:
@args:
@Returns:
<!-- ##### FUNCTION g_printf_string_upper_bound ##### -->