1 /* Decomposed printf argument list.
2 Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2011 Free Software
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /* This file can be parametrized with the following macros:
20 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
21 PRINTF_FETCHARGS Name of the function to be defined.
22 STATIC Set to 'static' to declare the function static. */
24 #ifndef PRINTF_FETCHARGS
29 #ifndef PRINTF_FETCHARGS
30 # include "printf-args.h"
37 PRINTF_FETCHARGS (va_list args, arguments *a)
42 for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
46 ap->a.a_schar = va_arg (args, /*signed char*/ int);
49 ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
52 ap->a.a_short = va_arg (args, /*short*/ int);
55 ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
58 ap->a.a_int = va_arg (args, int);
61 ap->a.a_uint = va_arg (args, unsigned int);
64 ap->a.a_longint = va_arg (args, long int);
67 ap->a.a_ulongint = va_arg (args, unsigned long int);
69 #if HAVE_LONG_LONG_INT
70 case TYPE_LONGLONGINT:
71 ap->a.a_longlongint = va_arg (args, long long int);
73 case TYPE_ULONGLONGINT:
74 ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
78 ap->a.a_double = va_arg (args, double);
81 ap->a.a_longdouble = va_arg (args, long double);
84 ap->a.a_char = va_arg (args, int);
88 /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by
89 default argument promotions", this is not the case in mingw32,
90 where wint_t is 'unsigned short'. */
92 (sizeof (wint_t) < sizeof (int)
93 ? (wint_t) va_arg (args, int)
94 : va_arg (args, wint_t));
98 ap->a.a_string = va_arg (args, const char *);
99 /* A null pointer is an invalid argument for "%s", but in practice
100 it occurs quite frequently in printf statements that produce
101 debug output. Use a fallback in this case. */
102 if (ap->a.a_string == NULL)
103 ap->a.a_string = "(NULL)";
106 case TYPE_WIDE_STRING:
107 ap->a.a_wide_string = va_arg (args, const wchar_t *);
108 /* A null pointer is an invalid argument for "%ls", but in practice
109 it occurs quite frequently in printf statements that produce
110 debug output. Use a fallback in this case. */
111 if (ap->a.a_wide_string == NULL)
113 static const wchar_t wide_null_string[] =
116 (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L',
120 ap->a.a_wide_string = wide_null_string;
125 ap->a.a_pointer = va_arg (args, void *);
127 case TYPE_COUNT_SCHAR_POINTER:
128 ap->a.a_count_schar_pointer = va_arg (args, signed char *);
130 case TYPE_COUNT_SHORT_POINTER:
131 ap->a.a_count_short_pointer = va_arg (args, short *);
133 case TYPE_COUNT_INT_POINTER:
134 ap->a.a_count_int_pointer = va_arg (args, int *);
136 case TYPE_COUNT_LONGINT_POINTER:
137 ap->a.a_count_longint_pointer = va_arg (args, long int *);
139 #if HAVE_LONG_LONG_INT
140 case TYPE_COUNT_LONGLONGINT_POINTER:
141 ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
145 /* The unistdio extensions. */
147 ap->a.a_u8_string = va_arg (args, const uint8_t *);
148 /* A null pointer is an invalid argument for "%U", but in practice
149 it occurs quite frequently in printf statements that produce
150 debug output. Use a fallback in this case. */
151 if (ap->a.a_u8_string == NULL)
153 static const uint8_t u8_null_string[] =
154 { '(', 'N', 'U', 'L', 'L', ')', 0 };
155 ap->a.a_u8_string = u8_null_string;
158 case TYPE_U16_STRING:
159 ap->a.a_u16_string = va_arg (args, const uint16_t *);
160 /* A null pointer is an invalid argument for "%lU", but in practice
161 it occurs quite frequently in printf statements that produce
162 debug output. Use a fallback in this case. */
163 if (ap->a.a_u16_string == NULL)
165 static const uint16_t u16_null_string[] =
166 { '(', 'N', 'U', 'L', 'L', ')', 0 };
167 ap->a.a_u16_string = u16_null_string;
170 case TYPE_U32_STRING:
171 ap->a.a_u32_string = va_arg (args, const uint32_t *);
172 /* A null pointer is an invalid argument for "%llU", but in practice
173 it occurs quite frequently in printf statements that produce
174 debug output. Use a fallback in this case. */
175 if (ap->a.a_u32_string == NULL)
177 static const uint32_t u32_null_string[] =
178 { '(', 'N', 'U', 'L', 'L', ')', 0 };
179 ap->a.a_u32_string = u32_null_string;