Remove developer script not needed in git repository
[glib.git] / glib / gnulib / printf.c
blob242740a9d71c57f83716ce2fa8f700bdc8d35c8f
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 2003 Matthias Clasen
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, see <http://www.gnu.org/licenses/>.
19 * Modified by the GLib Team and others 2003. See the AUTHORS
20 * file for a list of people on the GLib Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GLib at ftp://ftp.gtk.org/pub/gtk/.
25 #include <config.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include "g-gnulib.h"
30 #include "vasnprintf.h"
31 #include "printf.h"
33 int _g_gnulib_printf (char const *format, ...)
35 va_list args;
36 int retval;
38 va_start (args, format);
39 retval = _g_gnulib_vprintf (format, args);
40 va_end (args);
42 return retval;
45 int _g_gnulib_fprintf (FILE *file, char const *format, ...)
47 va_list args;
48 int retval;
50 va_start (args, format);
51 retval = _g_gnulib_vfprintf (file, format, args);
52 va_end (args);
54 return retval;
57 int _g_gnulib_sprintf (char *string, char const *format, ...)
59 va_list args;
60 int retval;
62 va_start (args, format);
63 retval = _g_gnulib_vsprintf (string, format, args);
64 va_end (args);
66 return retval;
69 int _g_gnulib_snprintf (char *string, size_t n, char const *format, ...)
71 va_list args;
72 int retval;
74 va_start (args, format);
75 retval = _g_gnulib_vsnprintf (string, n, format, args);
76 va_end (args);
78 return retval;
81 int _g_gnulib_vprintf (char const *format, va_list args)
83 return _g_gnulib_vfprintf (stdout, format, args);
86 int _g_gnulib_vfprintf (FILE *file, char const *format, va_list args)
88 char *result;
89 size_t length, rlength;
91 result = vasnprintf (NULL, &length, format, args);
92 if (result == NULL)
93 return -1;
95 rlength = fwrite (result, 1, length, file);
96 free (result);
98 return rlength;
101 int _g_gnulib_vsprintf (char *string, char const *format, va_list args)
103 char *result;
104 size_t length;
106 result = vasnprintf (NULL, &length, format, args);
107 if (result == NULL)
108 return -1;
110 memcpy (string, result, length + 1);
111 free (result);
113 return length;
116 int _g_gnulib_vsnprintf (char *string, size_t n, char const *format, va_list args)
118 char *result;
119 size_t length;
121 result = vasnprintf (NULL, &length, format, args);
122 if (result == NULL)
123 return -1;
125 if (n > 0)
127 memcpy (string, result, MIN(length + 1, n));
128 string[n - 1] = 0;
131 free (result);
133 return length;
136 int _g_gnulib_vasprintf (char **result, char const *format, va_list args)
138 size_t length;
140 *result = vasnprintf (NULL, &length, format, args);
141 if (*result == NULL)
142 return -1;
144 return length;