1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997, 2002 Peter Mattis, Red Hat, Inc.
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.
26 #include "gprintfint.h"
30 * @format: the format string. See the printf() documentation.
31 * @Varargs: the arguments to insert in the output.
33 * An implementation of the standard printf() function which supports
34 * positional parameters, as specified in the Single Unix Specification.
36 * Returns: the number of characters printed.
39 g_printf (gchar const *fmt,
46 retval = g_vprintf (fmt, args);
54 * @file: the stream to write to.
55 * @format: the format string. See the printf() documentation.
56 * @Varargs: the arguments to insert in the output.
58 * An implementation of the standard fprintf() function which supports
59 * positional parameters, as specified in the Single Unix Specification.
61 * Returns: the number of characters printed.
64 g_fprintf (FILE *file,
72 retval = g_vfprintf (file, fmt, args);
80 * @string: the buffer to hold the output.
81 * @format: the format string. See the printf() documentation.
82 * @Varargs: the arguments to insert in the output.
84 * An implementation of the standard sprintf() function which supports
85 * positional parameters, as specified in the Single Unix Specification.
87 * Returns: the number of characters printed.
90 g_sprintf (gchar *str,
98 retval = g_vsprintf (str, fmt, args);
106 * @string: the buffer to hold the output.
107 * @n: the maximum number of characters to produce (including the
108 * terminating nul character).
109 * @format: the format string. See the printf() documentation.
110 * @Varargs: the arguments to insert in the output.
112 * A safer form of the standard sprintf() function. The output is guaranteed
113 * to not exceed @n characters (including the terminating nul character), so
114 * it is easy to ensure that a buffer overflow cannot occur.
116 * See also g_strdup_printf().
118 * In versions of GLib prior to 1.2.3, this function may return -1 if the
119 * output was truncated, and the truncated string may not be nul-terminated.
120 * In versions prior to 1.3.12, this function returns the length of the output
123 * The return value of g_snprintf() conforms to the snprintf()
124 * function as standardized in ISO C99. Note that this is different from
125 * traditional snprintf(), which returns the length of the output string.
127 * The format string may contain positional parameters, as specified in
128 * the Single Unix Specification.
130 * Returns: the number of characters which would be produced if the buffer
134 g_snprintf (gchar *str,
142 va_start (args, fmt);
143 retval = g_vsnprintf (str, n, fmt, args);
151 * @format: the format string. See the printf() documentation.
152 * @args: the list of arguments to insert in the output.
154 * An implementation of the standard vprintf() function which supports
155 * positional parameters, as specified in the Single Unix Specification.
157 * Returns: the number of characters printed.
160 g_vprintf (gchar const *fmt,
163 g_return_val_if_fail (fmt != NULL, 0);
165 return _g_vprintf (fmt, args);
170 * @file: the stream to write to.
171 * @format: the format string. See the printf() documentation.
172 * @args: the list of arguments to insert in the output.
174 * An implementation of the standard fprintf() function which supports
175 * positional parameters, as specified in the Single Unix Specification.
177 * Returns: the number of characters printed.
180 g_vfprintf (FILE *file,
184 g_return_val_if_fail (fmt != NULL, 0);
186 return _g_vfprintf (file, fmt, args);
191 * @string: the buffer to hold the output.
192 * @format: the format string. See the printf() documentation.
193 * @args: the list of arguments to insert in the output.
195 * An implementation of the standard vsprintf() function which supports
196 * positional parameters, as specified in the Single Unix Specification.
198 * Returns: the number of characters printed.
201 g_vsprintf (gchar *str,
205 g_return_val_if_fail (str != NULL, 0);
206 g_return_val_if_fail (fmt != NULL, 0);
208 return _g_vsprintf (str, fmt, args);
213 * @string: the buffer to hold the output.
214 * @n: the maximum number of characters to produce (including the
215 * terminating nul character).
216 * @format: the format string. See the printf() documentation.
217 * @args: the list of arguments to insert in the output.
219 * A safer form of the standard vsprintf() function. The output is guaranteed
220 * to not exceed @n characters (including the terminating nul character), so
221 * it is easy to ensure that a buffer overflow cannot occur.
223 * See also g_strdup_vprintf().
225 * In versions of GLib prior to 1.2.3, this function may return -1 if the
226 * output was truncated, and the truncated string may not be nul-terminated.
227 * In versions prior to 1.3.12, this function returns the length of the output
230 * The return value of g_vsnprintf() conforms to the vsnprintf() function
231 * as standardized in ISO C99. Note that this is different from traditional
232 * vsnprintf(), which returns the length of the output string.
234 * The format string may contain positional parameters, as specified in
235 * the Single Unix Specification.
237 * Returns: the number of characters which would be produced if the buffer
241 g_vsnprintf (gchar *str,
246 g_return_val_if_fail (n == 0 || str != NULL, 0);
247 g_return_val_if_fail (fmt != NULL, 0);
249 return _g_vsnprintf (str, n, fmt, args);