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.
41 g_printf (gchar
const *fmt
,
48 retval
= g_vprintf (fmt
, args
);
56 * @file: the stream to write to.
57 * @format: the format string. See the printf() documentation.
58 * @Varargs: the arguments to insert in the output.
60 * An implementation of the standard fprintf() function which supports
61 * positional parameters, as specified in the Single Unix Specification.
63 * Returns: the number of characters printed.
68 g_fprintf (FILE *file
,
76 retval
= g_vfprintf (file
, fmt
, args
);
84 * @string: the buffer to hold the output.
85 * @format: the format string. See the printf() documentation.
86 * @Varargs: the arguments to insert in the output.
88 * An implementation of the standard sprintf() function which supports
89 * positional parameters, as specified in the Single Unix Specification.
91 * Returns: the number of characters printed.
96 g_sprintf (gchar
*str
,
103 va_start (args
, fmt
);
104 retval
= g_vsprintf (str
, fmt
, args
);
112 * @string: the buffer to hold the output.
113 * @n: the maximum number of characters to produce (including the
114 * terminating nul character).
115 * @format: the format string. See the printf() documentation.
116 * @Varargs: the arguments to insert in the output.
118 * A safer form of the standard sprintf() function. The output is guaranteed
119 * to not exceed @n characters (including the terminating nul character), so
120 * it is easy to ensure that a buffer overflow cannot occur.
122 * See also g_strdup_printf().
124 * In versions of GLib prior to 1.2.3, this function may return -1 if the
125 * output was truncated, and the truncated string may not be nul-terminated.
126 * In versions prior to 1.3.12, this function returns the length of the output
129 * The return value of g_snprintf() conforms to the snprintf()
130 * function as standardized in ISO C99. Note that this is different from
131 * traditional snprintf(), which returns the length of the output string.
133 * The format string may contain positional parameters, as specified in
134 * the Single Unix Specification.
136 * Returns: the number of characters which would be produced if the buffer
140 g_snprintf (gchar
*str
,
148 va_start (args
, fmt
);
149 retval
= g_vsnprintf (str
, n
, fmt
, args
);
157 * @format: the format string. See the printf() documentation.
158 * @args: the list of arguments to insert in the output.
160 * An implementation of the standard vprintf() function which supports
161 * positional parameters, as specified in the Single Unix Specification.
163 * Returns: the number of characters printed.
168 g_vprintf (gchar
const *fmt
,
171 g_return_val_if_fail (fmt
!= NULL
, 0);
173 return _g_vprintf (fmt
, args
);
178 * @file: the stream to write to.
179 * @format: the format string. See the printf() documentation.
180 * @args: the list of arguments to insert in the output.
182 * An implementation of the standard fprintf() function which supports
183 * positional parameters, as specified in the Single Unix Specification.
185 * Returns: the number of characters printed.
190 g_vfprintf (FILE *file
,
194 g_return_val_if_fail (fmt
!= NULL
, 0);
196 return _g_vfprintf (file
, fmt
, args
);
201 * @string: the buffer to hold the output.
202 * @format: the format string. See the printf() documentation.
203 * @args: the list of arguments to insert in the output.
205 * An implementation of the standard vsprintf() function which supports
206 * positional parameters, as specified in the Single Unix Specification.
208 * Returns: the number of characters printed.
213 g_vsprintf (gchar
*str
,
217 g_return_val_if_fail (str
!= NULL
, 0);
218 g_return_val_if_fail (fmt
!= NULL
, 0);
220 return _g_vsprintf (str
, fmt
, args
);
225 * @string: the buffer to hold the output.
226 * @n: the maximum number of characters to produce (including the
227 * terminating nul character).
228 * @format: the format string. See the printf() documentation.
229 * @args: the list of arguments to insert in the output.
231 * A safer form of the standard vsprintf() function. The output is guaranteed
232 * to not exceed @n characters (including the terminating nul character), so
233 * it is easy to ensure that a buffer overflow cannot occur.
235 * See also g_strdup_vprintf().
237 * In versions of GLib prior to 1.2.3, this function may return -1 if the
238 * output was truncated, and the truncated string may not be nul-terminated.
239 * In versions prior to 1.3.12, this function returns the length of the output
242 * The return value of g_vsnprintf() conforms to the vsnprintf() function
243 * as standardized in ISO C99. Note that this is different from traditional
244 * vsnprintf(), which returns the length of the output string.
246 * The format string may contain positional parameters, as specified in
247 * the Single Unix Specification.
249 * Returns: the number of characters which would be produced if the buffer
253 g_vsnprintf (gchar
*str
,
258 g_return_val_if_fail (n
== 0 || str
!= NULL
, 0);
259 g_return_val_if_fail (fmt
!= NULL
, 0);
261 return _g_vsnprintf (str
, n
, fmt
, args
);