3 /* Formatted output to strings, using POSIX/XSI format strings with positions.
4 Copyright (C) 2003 Free Software Foundation, Inc.
5 Written by Bruno Haible <bruno@clisp.org>, 2003.
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Library General Public License as published
9 by the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 # define alloca __builtin_alloca
28 # define HAVE_ALLOCA 1
32 # define alloca _alloca
34 # if defined HAVE_ALLOCA_H || defined _LIBC
50 #if !HAVE_POSIX_PRINTF
55 /* When building a DLL, we must export some functions. Note that because
56 the functions are only defined for binary backward compatibility, we
57 don't need to use __declspec(dllimport) in any case. */
58 #if defined _MSC_VER && BUILDING_DLL
59 # define DLL_EXPORTED __declspec(dllexport)
66 /* Define auxiliary functions declared in "printf-args.h". */
67 #include "printf-args.c"
69 /* Define auxiliary functions declared in "printf-parse.h". */
70 #include "printf-parse.c"
72 /* Define functions declared in "vasnprintf.h". */
73 #define vasnprintf libintl_vasnprintf
74 #include "vasnprintf.c"
75 #if 0 /* not needed */
76 #define asnprintf libintl_asnprintf
77 #include "asnprintf.c"
82 libintl_vfprintf (FILE *stream
, const char *format
, va_list args
)
84 if (strchr (format
, '$') == NULL
)
85 return vfprintf (stream
, format
, args
);
89 char *result
= libintl_vasnprintf (NULL
, &length
, format
, args
);
93 if (fwrite (result
, 1, length
, stream
) == length
)
103 libintl_fprintf (FILE *stream
, const char *format
, ...)
108 va_start (args
, format
);
109 retval
= libintl_vfprintf (stream
, format
, args
);
116 libintl_vprintf (const char *format
, va_list args
)
118 return libintl_vfprintf (stdout
, format
, args
);
123 libintl_printf (const char *format
, ...)
128 va_start (args
, format
);
129 retval
= libintl_vprintf (format
, args
);
136 libintl_vsprintf (char *resultbuf
, const char *format
, va_list args
)
138 if (strchr (format
, '$') == NULL
)
139 return vsprintf (resultbuf
, format
, args
);
142 size_t length
= (size_t) ~0 / (4 * sizeof (char));
143 char *result
= libintl_vasnprintf (resultbuf
, &length
, format
, args
);
144 if (result
!= resultbuf
)
156 libintl_sprintf (char *resultbuf
, const char *format
, ...)
161 va_start (args
, format
);
162 retval
= libintl_vsprintf (resultbuf
, format
, args
);
169 # if HAVE_DECL__SNPRINTF
171 # define system_vsnprintf _vsnprintf
174 # define system_vsnprintf vsnprintf
179 libintl_vsnprintf (char *resultbuf
, size_t length
, const char *format
, va_list args
)
181 if (strchr (format
, '$') == NULL
)
182 return system_vsnprintf (resultbuf
, length
, format
, args
);
185 size_t maxlength
= length
;
186 char *result
= libintl_vasnprintf (resultbuf
, &length
, format
, args
);
187 if (result
!= resultbuf
)
191 if (length
< maxlength
)
193 memcpy (resultbuf
, result
, maxlength
- 1);
194 resultbuf
[maxlength
- 1] = '\0';
206 libintl_snprintf (char *resultbuf
, size_t length
, const char *format
, ...)
211 va_start (args
, format
);
212 retval
= libintl_vsnprintf (resultbuf
, length
, format
, args
);
223 libintl_vasprintf (char **resultp
, const char *format
, va_list args
)
226 char *result
= libintl_vasnprintf (NULL
, &length
, format
, args
);
235 libintl_asprintf (char **resultp
, const char *format
, ...)
240 va_start (args
, format
);
241 retval
= libintl_vasprintf (resultp
, format
, args
);
252 #define WIDE_CHAR_VERSION 1
254 /* Define auxiliary functions declared in "wprintf-parse.h". */
255 #include "printf-parse.c"
257 /* Define functions declared in "vasnprintf.h". */
258 #define vasnwprintf libintl_vasnwprintf
259 #include "vasnprintf.c"
260 #if 0 /* not needed */
261 #define asnwprintf libintl_asnwprintf
262 #include "asnprintf.c"
265 # if HAVE_DECL__SNWPRINTF
267 # define system_vswprintf _vsnwprintf
270 # define system_vswprintf vswprintf
275 libintl_vfwprintf (FILE *stream
, const wchar_t *format
, va_list args
)
277 if (wcschr (format
, '$') == NULL
)
278 return vfwprintf (stream
, format
, args
);
282 wchar_t *result
= libintl_vasnwprintf (NULL
, &length
, format
, args
);
287 for (i
= 0; i
< length
; i
++)
288 if (fputwc (result
[i
], stream
) == WEOF
)
300 libintl_fwprintf (FILE *stream
, const wchar_t *format
, ...)
305 va_start (args
, format
);
306 retval
= libintl_vfwprintf (stream
, format
, args
);
313 libintl_vwprintf (const wchar_t *format
, va_list args
)
315 return libintl_vfwprintf (stdout
, format
, args
);
320 libintl_wprintf (const wchar_t *format
, ...)
325 va_start (args
, format
);
326 retval
= libintl_vwprintf (format
, args
);
333 libintl_vswprintf (wchar_t *resultbuf
, size_t length
, const wchar_t *format
, va_list args
)
335 if (wcschr (format
, '$') == NULL
)
336 return system_vswprintf (resultbuf
, length
, format
, args
);
339 size_t maxlength
= length
;
340 wchar_t *result
= libintl_vasnwprintf (resultbuf
, &length
, format
, args
);
341 if (result
!= resultbuf
)
345 if (length
< maxlength
)
347 memcpy (resultbuf
, result
, (maxlength
- 1) * sizeof (wchar_t));
348 resultbuf
[maxlength
- 1] = 0;
360 libintl_swprintf (wchar_t *resultbuf
, size_t length
, const wchar_t *format
, ...)
365 va_start (args
, format
);
366 retval
= libintl_vswprintf (resultbuf
, length
, format
, args
);