* sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h: Likewise.
[glibc.git] / stdio-common / vfprintf.c
blob83da710a2a2fa30216f27079e86265d93e20855b
1 /* Copyright (C) 1991-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C 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.1 of the License, or (at your option) any later version.
9 The GNU C 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 the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <ctype.h>
20 #include <limits.h>
21 #include <printf.h>
22 #include <stdarg.h>
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <errno.h>
27 #include <wchar.h>
28 #include <bits/libc-lock.h>
29 #include <sys/param.h>
30 #include "_itoa.h"
31 #include <locale/localeinfo.h>
32 #include <stdio.h>
34 /* This code is shared between the standard stdio implementation found
35 in GNU C library and the libio implementation originally found in
36 GNU libg++.
38 Beside this it is also shared between the normal and wide character
39 implementation as defined in ISO/IEC 9899:1990/Amendment 1:1995. */
42 #include <libioP.h>
43 #define FILE _IO_FILE
44 #undef va_list
45 #define va_list _IO_va_list
46 #undef BUFSIZ
47 #define BUFSIZ _IO_BUFSIZ
48 #define ARGCHECK(S, Format) \
49 do \
50 { \
51 /* Check file argument for consistence. */ \
52 CHECK_FILE (S, -1); \
53 if (S->_flags & _IO_NO_WRITES) \
54 { \
55 __set_errno (EBADF); \
56 return -1; \
57 } \
58 if (Format == NULL) \
59 { \
60 MAYBE_SET_EINVAL; \
61 return -1; \
62 } \
63 } while (0)
64 #define UNBUFFERED_P(S) ((S)->_IO_file_flags & _IO_UNBUFFERED)
66 #ifndef COMPILE_WPRINTF
67 # define vfprintf _IO_vfprintf
68 # define CHAR_T char
69 # define UCHAR_T unsigned char
70 # define INT_T int
71 # define L_(Str) Str
72 # define ISDIGIT(Ch) ((unsigned int) ((Ch) - '0') < 10)
73 # define STR_LEN(Str) strlen (Str)
75 # define PUT(F, S, N) _IO_sputn ((F), (S), (N))
76 # define PAD(Padchar) \
77 if (width > 0) \
78 done += INTUSE(_IO_padn) (s, (Padchar), width)
79 # define PUTC(C, F) _IO_putc_unlocked (C, F)
80 # define ORIENT if (_IO_vtable_offset (s) == 0 && _IO_fwide (s, -1) != -1)\
81 return -1
82 #else
83 # define vfprintf _IO_vfwprintf
84 # define CHAR_T wchar_t
85 /* This is a hack!!! There should be a type uwchar_t. */
86 # define UCHAR_T unsigned int /* uwchar_t */
87 # define INT_T wint_t
88 # define L_(Str) L##Str
89 # define ISDIGIT(Ch) ((unsigned int) ((Ch) - L'0') < 10)
90 # define STR_LEN(Str) __wcslen (Str)
92 # include "_itowa.h"
94 # define PUT(F, S, N) _IO_sputn ((F), (S), (N))
95 # define PAD(Padchar) \
96 if (width > 0) \
97 done += _IO_wpadn (s, (Padchar), width)
98 # define PUTC(C, F) _IO_putwc_unlocked (C, F)
99 # define ORIENT if (_IO_fwide (s, 1) != 1) return -1
101 # define _itoa(Val, Buf, Base, Case) _itowa (Val, Buf, Base, Case)
102 # define _itoa_word(Val, Buf, Base, Case) _itowa_word (Val, Buf, Base, Case)
103 # undef EOF
104 # define EOF WEOF
105 #endif
107 #include "_i18n_number.h"
109 /* Include the shared code for parsing the format string. */
110 #include "printf-parse.h"
113 #define outchar(Ch) \
114 do \
116 register const INT_T outc = (Ch); \
117 if (PUTC (outc, s) == EOF) \
119 done = -1; \
120 goto all_done; \
122 else \
123 ++done; \
125 while (0)
127 #define outstring(String, Len) \
128 do \
130 if ((size_t) PUT (s, (String), (Len)) != (size_t) (Len)) \
132 done = -1; \
133 goto all_done; \
135 done += (Len); \
137 while (0)
139 /* For handling long_double and longlong we use the same flag. If
140 `long' and `long long' are effectively the same type define it to
141 zero. */
142 #if LONG_MAX == LONG_LONG_MAX
143 # define is_longlong 0
144 #else
145 # define is_longlong is_long_double
146 #endif
148 /* If `long' and `int' is effectively the same type we don't have to
149 handle `long separately. */
150 #if INT_MAX == LONG_MAX
151 # define is_long_num 0
152 #else
153 # define is_long_num is_long
154 #endif
157 /* Global variables. */
158 static const CHAR_T null[] = L_("(null)");
161 /* Helper function to provide temporary buffering for unbuffered streams. */
162 static int buffered_vfprintf (FILE *stream, const CHAR_T *fmt, va_list)
163 __THROW __attribute__ ((noinline)) internal_function;
165 /* Handle unknown format specifier. */
166 static int printf_unknown (FILE *, const struct printf_info *,
167 const void *const *) __THROW;
169 /* Group digits of number string. */
170 #ifdef COMPILE_WPRINTF
171 static CHAR_T *group_number (CHAR_T *, CHAR_T *, const char *, wchar_t)
172 __THROW internal_function;
173 #else
174 static CHAR_T *group_number (CHAR_T *, CHAR_T *, const char *, const char *)
175 __THROW internal_function;
176 #endif
179 /* The function itself. */
181 vfprintf (FILE *s, const CHAR_T *format, va_list ap)
183 /* The character used as thousands separator. */
184 #ifdef COMPILE_WPRINTF
185 wchar_t thousands_sep = L'\0';
186 #else
187 const char *thousands_sep = NULL;
188 #endif
190 /* The string describing the size of groups of digits. */
191 const char *grouping;
193 /* Place to accumulate the result. */
194 int done;
196 /* Current character in format string. */
197 const UCHAR_T *f;
199 /* End of leading constant string. */
200 const UCHAR_T *lead_str_end;
202 /* Points to next format specifier. */
203 const UCHAR_T *end_of_spec;
205 /* Buffer intermediate results. */
206 CHAR_T work_buffer[1000];
207 CHAR_T *workstart = NULL;
208 CHAR_T *workend;
210 /* State for restartable multibyte character handling functions. */
211 #ifndef COMPILE_WPRINTF
212 mbstate_t mbstate;
213 #endif
215 /* We have to save the original argument pointer. */
216 va_list ap_save;
218 /* Count number of specifiers we already processed. */
219 int nspecs_done;
221 /* For the %m format we may need the current `errno' value. */
222 int save_errno = errno;
224 /* 1 if format is in read-only memory, -1 if it is in writable memory,
225 0 if unknown. */
226 int readonly_format = 0;
228 /* This table maps a character into a number representing a
229 class. In each step there is a destination label for each
230 class. */
231 static const int jump_table[] =
233 /* ' ' */ 1, 0, 0, /* '#' */ 4,
234 0, /* '%' */ 14, 0, /* '\''*/ 6,
235 0, 0, /* '*' */ 7, /* '+' */ 2,
236 0, /* '-' */ 3, /* '.' */ 9, 0,
237 /* '0' */ 5, /* '1' */ 8, /* '2' */ 8, /* '3' */ 8,
238 /* '4' */ 8, /* '5' */ 8, /* '6' */ 8, /* '7' */ 8,
239 /* '8' */ 8, /* '9' */ 8, 0, 0,
240 0, 0, 0, 0,
241 0, /* 'A' */ 26, 0, /* 'C' */ 25,
242 0, /* 'E' */ 19, /* F */ 19, /* 'G' */ 19,
243 0, /* 'I' */ 29, 0, 0,
244 /* 'L' */ 12, 0, 0, 0,
245 0, 0, 0, /* 'S' */ 21,
246 0, 0, 0, 0,
247 /* 'X' */ 18, 0, /* 'Z' */ 13, 0,
248 0, 0, 0, 0,
249 0, /* 'a' */ 26, 0, /* 'c' */ 20,
250 /* 'd' */ 15, /* 'e' */ 19, /* 'f' */ 19, /* 'g' */ 19,
251 /* 'h' */ 10, /* 'i' */ 15, /* 'j' */ 28, 0,
252 /* 'l' */ 11, /* 'm' */ 24, /* 'n' */ 23, /* 'o' */ 17,
253 /* 'p' */ 22, /* 'q' */ 12, 0, /* 's' */ 21,
254 /* 't' */ 27, /* 'u' */ 16, 0, 0,
255 /* 'x' */ 18, 0, /* 'z' */ 13
258 #define NOT_IN_JUMP_RANGE(Ch) ((Ch) < L_(' ') || (Ch) > L_('z'))
259 #define CHAR_CLASS(Ch) (jump_table[(INT_T) (Ch) - L_(' ')])
260 #ifdef SHARED
261 /* 'int' is enough and it saves some space on 64 bit systems. */
262 # define JUMP_TABLE_TYPE const int
263 # define JUMP(ChExpr, table) \
264 do \
266 int offset; \
267 void *__unbounded ptr; \
268 spec = (ChExpr); \
269 offset = NOT_IN_JUMP_RANGE (spec) ? REF (form_unknown) \
270 : table[CHAR_CLASS (spec)]; \
271 ptr = &&do_form_unknown + offset; \
272 goto *ptr; \
274 while (0)
275 #else
276 # define JUMP_TABLE_TYPE const void *const
277 # define JUMP(ChExpr, table) \
278 do \
280 const void *__unbounded ptr; \
281 spec = (ChExpr); \
282 ptr = NOT_IN_JUMP_RANGE (spec) ? REF (form_unknown) \
283 : table[CHAR_CLASS (spec)]; \
284 goto *ptr; \
286 while (0)
287 #endif
289 #define STEP0_3_TABLE \
290 /* Step 0: at the beginning. */ \
291 static JUMP_TABLE_TYPE step0_jumps[30] = \
293 REF (form_unknown), \
294 REF (flag_space), /* for ' ' */ \
295 REF (flag_plus), /* for '+' */ \
296 REF (flag_minus), /* for '-' */ \
297 REF (flag_hash), /* for '<hash>' */ \
298 REF (flag_zero), /* for '0' */ \
299 REF (flag_quote), /* for '\'' */ \
300 REF (width_asterics), /* for '*' */ \
301 REF (width), /* for '1'...'9' */ \
302 REF (precision), /* for '.' */ \
303 REF (mod_half), /* for 'h' */ \
304 REF (mod_long), /* for 'l' */ \
305 REF (mod_longlong), /* for 'L', 'q' */ \
306 REF (mod_size_t), /* for 'z', 'Z' */ \
307 REF (form_percent), /* for '%' */ \
308 REF (form_integer), /* for 'd', 'i' */ \
309 REF (form_unsigned), /* for 'u' */ \
310 REF (form_octal), /* for 'o' */ \
311 REF (form_hexa), /* for 'X', 'x' */ \
312 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
313 REF (form_character), /* for 'c' */ \
314 REF (form_string), /* for 's', 'S' */ \
315 REF (form_pointer), /* for 'p' */ \
316 REF (form_number), /* for 'n' */ \
317 REF (form_strerror), /* for 'm' */ \
318 REF (form_wcharacter), /* for 'C' */ \
319 REF (form_floathex), /* for 'A', 'a' */ \
320 REF (mod_ptrdiff_t), /* for 't' */ \
321 REF (mod_intmax_t), /* for 'j' */ \
322 REF (flag_i18n), /* for 'I' */ \
323 }; \
324 /* Step 1: after processing width. */ \
325 static JUMP_TABLE_TYPE step1_jumps[30] = \
327 REF (form_unknown), \
328 REF (form_unknown), /* for ' ' */ \
329 REF (form_unknown), /* for '+' */ \
330 REF (form_unknown), /* for '-' */ \
331 REF (form_unknown), /* for '<hash>' */ \
332 REF (form_unknown), /* for '0' */ \
333 REF (form_unknown), /* for '\'' */ \
334 REF (form_unknown), /* for '*' */ \
335 REF (form_unknown), /* for '1'...'9' */ \
336 REF (precision), /* for '.' */ \
337 REF (mod_half), /* for 'h' */ \
338 REF (mod_long), /* for 'l' */ \
339 REF (mod_longlong), /* for 'L', 'q' */ \
340 REF (mod_size_t), /* for 'z', 'Z' */ \
341 REF (form_percent), /* for '%' */ \
342 REF (form_integer), /* for 'd', 'i' */ \
343 REF (form_unsigned), /* for 'u' */ \
344 REF (form_octal), /* for 'o' */ \
345 REF (form_hexa), /* for 'X', 'x' */ \
346 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
347 REF (form_character), /* for 'c' */ \
348 REF (form_string), /* for 's', 'S' */ \
349 REF (form_pointer), /* for 'p' */ \
350 REF (form_number), /* for 'n' */ \
351 REF (form_strerror), /* for 'm' */ \
352 REF (form_wcharacter), /* for 'C' */ \
353 REF (form_floathex), /* for 'A', 'a' */ \
354 REF (mod_ptrdiff_t), /* for 't' */ \
355 REF (mod_intmax_t), /* for 'j' */ \
356 REF (form_unknown) /* for 'I' */ \
357 }; \
358 /* Step 2: after processing precision. */ \
359 static JUMP_TABLE_TYPE step2_jumps[30] = \
361 REF (form_unknown), \
362 REF (form_unknown), /* for ' ' */ \
363 REF (form_unknown), /* for '+' */ \
364 REF (form_unknown), /* for '-' */ \
365 REF (form_unknown), /* for '<hash>' */ \
366 REF (form_unknown), /* for '0' */ \
367 REF (form_unknown), /* for '\'' */ \
368 REF (form_unknown), /* for '*' */ \
369 REF (form_unknown), /* for '1'...'9' */ \
370 REF (form_unknown), /* for '.' */ \
371 REF (mod_half), /* for 'h' */ \
372 REF (mod_long), /* for 'l' */ \
373 REF (mod_longlong), /* for 'L', 'q' */ \
374 REF (mod_size_t), /* for 'z', 'Z' */ \
375 REF (form_percent), /* for '%' */ \
376 REF (form_integer), /* for 'd', 'i' */ \
377 REF (form_unsigned), /* for 'u' */ \
378 REF (form_octal), /* for 'o' */ \
379 REF (form_hexa), /* for 'X', 'x' */ \
380 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
381 REF (form_character), /* for 'c' */ \
382 REF (form_string), /* for 's', 'S' */ \
383 REF (form_pointer), /* for 'p' */ \
384 REF (form_number), /* for 'n' */ \
385 REF (form_strerror), /* for 'm' */ \
386 REF (form_wcharacter), /* for 'C' */ \
387 REF (form_floathex), /* for 'A', 'a' */ \
388 REF (mod_ptrdiff_t), /* for 't' */ \
389 REF (mod_intmax_t), /* for 'j' */ \
390 REF (form_unknown) /* for 'I' */ \
391 }; \
392 /* Step 3a: after processing first 'h' modifier. */ \
393 static JUMP_TABLE_TYPE step3a_jumps[30] = \
395 REF (form_unknown), \
396 REF (form_unknown), /* for ' ' */ \
397 REF (form_unknown), /* for '+' */ \
398 REF (form_unknown), /* for '-' */ \
399 REF (form_unknown), /* for '<hash>' */ \
400 REF (form_unknown), /* for '0' */ \
401 REF (form_unknown), /* for '\'' */ \
402 REF (form_unknown), /* for '*' */ \
403 REF (form_unknown), /* for '1'...'9' */ \
404 REF (form_unknown), /* for '.' */ \
405 REF (mod_halfhalf), /* for 'h' */ \
406 REF (form_unknown), /* for 'l' */ \
407 REF (form_unknown), /* for 'L', 'q' */ \
408 REF (form_unknown), /* for 'z', 'Z' */ \
409 REF (form_percent), /* for '%' */ \
410 REF (form_integer), /* for 'd', 'i' */ \
411 REF (form_unsigned), /* for 'u' */ \
412 REF (form_octal), /* for 'o' */ \
413 REF (form_hexa), /* for 'X', 'x' */ \
414 REF (form_unknown), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
415 REF (form_unknown), /* for 'c' */ \
416 REF (form_unknown), /* for 's', 'S' */ \
417 REF (form_unknown), /* for 'p' */ \
418 REF (form_number), /* for 'n' */ \
419 REF (form_unknown), /* for 'm' */ \
420 REF (form_unknown), /* for 'C' */ \
421 REF (form_unknown), /* for 'A', 'a' */ \
422 REF (form_unknown), /* for 't' */ \
423 REF (form_unknown), /* for 'j' */ \
424 REF (form_unknown) /* for 'I' */ \
425 }; \
426 /* Step 3b: after processing first 'l' modifier. */ \
427 static JUMP_TABLE_TYPE step3b_jumps[30] = \
429 REF (form_unknown), \
430 REF (form_unknown), /* for ' ' */ \
431 REF (form_unknown), /* for '+' */ \
432 REF (form_unknown), /* for '-' */ \
433 REF (form_unknown), /* for '<hash>' */ \
434 REF (form_unknown), /* for '0' */ \
435 REF (form_unknown), /* for '\'' */ \
436 REF (form_unknown), /* for '*' */ \
437 REF (form_unknown), /* for '1'...'9' */ \
438 REF (form_unknown), /* for '.' */ \
439 REF (form_unknown), /* for 'h' */ \
440 REF (mod_longlong), /* for 'l' */ \
441 REF (form_unknown), /* for 'L', 'q' */ \
442 REF (form_unknown), /* for 'z', 'Z' */ \
443 REF (form_percent), /* for '%' */ \
444 REF (form_integer), /* for 'd', 'i' */ \
445 REF (form_unsigned), /* for 'u' */ \
446 REF (form_octal), /* for 'o' */ \
447 REF (form_hexa), /* for 'X', 'x' */ \
448 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
449 REF (form_character), /* for 'c' */ \
450 REF (form_string), /* for 's', 'S' */ \
451 REF (form_pointer), /* for 'p' */ \
452 REF (form_number), /* for 'n' */ \
453 REF (form_strerror), /* for 'm' */ \
454 REF (form_wcharacter), /* for 'C' */ \
455 REF (form_floathex), /* for 'A', 'a' */ \
456 REF (form_unknown), /* for 't' */ \
457 REF (form_unknown), /* for 'j' */ \
458 REF (form_unknown) /* for 'I' */ \
461 #define STEP4_TABLE \
462 /* Step 4: processing format specifier. */ \
463 static JUMP_TABLE_TYPE step4_jumps[30] = \
465 REF (form_unknown), \
466 REF (form_unknown), /* for ' ' */ \
467 REF (form_unknown), /* for '+' */ \
468 REF (form_unknown), /* for '-' */ \
469 REF (form_unknown), /* for '<hash>' */ \
470 REF (form_unknown), /* for '0' */ \
471 REF (form_unknown), /* for '\'' */ \
472 REF (form_unknown), /* for '*' */ \
473 REF (form_unknown), /* for '1'...'9' */ \
474 REF (form_unknown), /* for '.' */ \
475 REF (form_unknown), /* for 'h' */ \
476 REF (form_unknown), /* for 'l' */ \
477 REF (form_unknown), /* for 'L', 'q' */ \
478 REF (form_unknown), /* for 'z', 'Z' */ \
479 REF (form_percent), /* for '%' */ \
480 REF (form_integer), /* for 'd', 'i' */ \
481 REF (form_unsigned), /* for 'u' */ \
482 REF (form_octal), /* for 'o' */ \
483 REF (form_hexa), /* for 'X', 'x' */ \
484 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
485 REF (form_character), /* for 'c' */ \
486 REF (form_string), /* for 's', 'S' */ \
487 REF (form_pointer), /* for 'p' */ \
488 REF (form_number), /* for 'n' */ \
489 REF (form_strerror), /* for 'm' */ \
490 REF (form_wcharacter), /* for 'C' */ \
491 REF (form_floathex), /* for 'A', 'a' */ \
492 REF (form_unknown), /* for 't' */ \
493 REF (form_unknown), /* for 'j' */ \
494 REF (form_unknown) /* for 'I' */ \
498 #define process_arg(fspec) \
499 /* Start real work. We know about all flags and modifiers and \
500 now process the wanted format specifier. */ \
501 LABEL (form_percent): \
502 /* Write a literal "%". */ \
503 outchar (L_('%')); \
504 break; \
506 LABEL (form_integer): \
507 /* Signed decimal integer. */ \
508 base = 10; \
510 if (is_longlong) \
512 long long int signed_number; \
514 if (fspec == NULL) \
515 signed_number = va_arg (ap, long long int); \
516 else \
517 signed_number = args_value[fspec->data_arg].pa_long_long_int; \
519 is_negative = signed_number < 0; \
520 number.longlong = is_negative ? (- signed_number) : signed_number; \
522 goto LABEL (longlong_number); \
524 else \
526 long int signed_number; \
528 if (fspec == NULL) \
530 if (is_long_num) \
531 signed_number = va_arg (ap, long int); \
532 else /* `char' and `short int' will be promoted to `int'. */ \
533 signed_number = va_arg (ap, int); \
535 else \
536 if (is_long_num) \
537 signed_number = args_value[fspec->data_arg].pa_long_int; \
538 else /* `char' and `short int' will be promoted to `int'. */ \
539 signed_number = args_value[fspec->data_arg].pa_int; \
541 is_negative = signed_number < 0; \
542 number.word = is_negative ? (- signed_number) : signed_number; \
544 goto LABEL (number); \
546 /* NOTREACHED */ \
548 LABEL (form_unsigned): \
549 /* Unsigned decimal integer. */ \
550 base = 10; \
551 goto LABEL (unsigned_number); \
552 /* NOTREACHED */ \
554 LABEL (form_octal): \
555 /* Unsigned octal integer. */ \
556 base = 8; \
557 goto LABEL (unsigned_number); \
558 /* NOTREACHED */ \
560 LABEL (form_hexa): \
561 /* Unsigned hexadecimal integer. */ \
562 base = 16; \
564 LABEL (unsigned_number): /* Unsigned number of base BASE. */ \
566 /* ISO specifies the `+' and ` ' flags only for signed \
567 conversions. */ \
568 is_negative = 0; \
569 showsign = 0; \
570 space = 0; \
572 if (is_longlong) \
574 if (fspec == NULL) \
575 number.longlong = va_arg (ap, unsigned long long int); \
576 else \
577 number.longlong = args_value[fspec->data_arg].pa_u_long_long_int; \
579 LABEL (longlong_number): \
580 if (prec < 0) \
581 /* Supply a default precision if none was given. */ \
582 prec = 1; \
583 else \
584 /* We have to take care for the '0' flag. If a precision \
585 is given it must be ignored. */ \
586 pad = L_(' '); \
588 /* If the precision is 0 and the number is 0 nothing has to \
589 be written for the number, except for the 'o' format in \
590 alternate form. */ \
591 if (prec == 0 && number.longlong == 0) \
593 string = workend; \
594 if (base == 8 && alt) \
595 *--string = L_('0'); \
597 else \
599 /* Put the number in WORK. */ \
600 string = _itoa (number.longlong, workend, base, \
601 spec == L_('X')); \
602 if (group && grouping) \
603 string = group_number (string, workend, grouping, \
604 thousands_sep); \
606 if (use_outdigits && base == 10) \
607 string = _i18n_number_rewrite (string, workend); \
609 /* Simplify further test for num != 0. */ \
610 number.word = number.longlong != 0; \
612 else \
614 if (fspec == NULL) \
616 if (is_long_num) \
617 number.word = va_arg (ap, unsigned long int); \
618 else if (is_char) \
619 number.word = (unsigned char) va_arg (ap, unsigned int); \
620 else if (!is_short) \
621 number.word = va_arg (ap, unsigned int); \
622 else \
623 number.word = (unsigned short int) va_arg (ap, unsigned int); \
625 else \
626 if (is_long_num) \
627 number.word = args_value[fspec->data_arg].pa_u_long_int; \
628 else if (is_char) \
629 number.word = (unsigned char) \
630 args_value[fspec->data_arg].pa_u_int; \
631 else if (!is_short) \
632 number.word = args_value[fspec->data_arg].pa_u_int; \
633 else \
634 number.word = (unsigned short int) \
635 args_value[fspec->data_arg].pa_u_int; \
637 LABEL (number): \
638 if (prec < 0) \
639 /* Supply a default precision if none was given. */ \
640 prec = 1; \
641 else \
642 /* We have to take care for the '0' flag. If a precision \
643 is given it must be ignored. */ \
644 pad = L_(' '); \
646 /* If the precision is 0 and the number is 0 nothing has to \
647 be written for the number, except for the 'o' format in \
648 alternate form. */ \
649 if (prec == 0 && number.word == 0) \
651 string = workend; \
652 if (base == 8 && alt) \
653 *--string = L_('0'); \
655 else \
657 /* Put the number in WORK. */ \
658 string = _itoa_word (number.word, workend, base, \
659 spec == L_('X')); \
660 if (group && grouping) \
661 string = group_number (string, workend, grouping, \
662 thousands_sep); \
664 if (use_outdigits && base == 10) \
665 string = _i18n_number_rewrite (string, workend); \
669 if (prec <= workend - string && number.word != 0 && alt && base == 8) \
670 /* Add octal marker. */ \
671 *--string = L_('0'); \
673 prec = MAX (0, prec - (workend - string)); \
675 if (!left) \
677 width -= workend - string + prec; \
679 if (number.word != 0 && alt && base == 16) \
680 /* Account for 0X hex marker. */ \
681 width -= 2; \
683 if (is_negative || showsign || space) \
684 --width; \
686 if (pad == L_(' ')) \
688 PAD (L_(' ')); \
689 width = 0; \
692 if (is_negative) \
693 outchar (L_('-')); \
694 else if (showsign) \
695 outchar (L_('+')); \
696 else if (space) \
697 outchar (L_(' ')); \
699 if (number.word != 0 && alt && base == 16) \
701 outchar (L_('0')); \
702 outchar (spec); \
705 width += prec; \
706 PAD (L_('0')); \
708 outstring (string, workend - string); \
710 break; \
712 else \
714 if (is_negative) \
716 outchar (L_('-')); \
717 --width; \
719 else if (showsign) \
721 outchar (L_('+')); \
722 --width; \
724 else if (space) \
726 outchar (L_(' ')); \
727 --width; \
730 if (number.word != 0 && alt && base == 16) \
732 outchar (L_('0')); \
733 outchar (spec); \
734 width -= 2; \
737 width -= workend - string + prec; \
739 if (prec > 0) \
741 int temp = width; \
742 width = prec; \
743 PAD (L_('0'));; \
744 width = temp; \
747 outstring (string, workend - string); \
749 PAD (L_(' ')); \
750 break; \
753 LABEL (form_float): \
755 /* Floating-point number. This is handled by printf_fp.c. */ \
756 const void *ptr; \
757 int function_done; \
759 if (fspec == NULL) \
761 struct printf_info info = { .prec = prec, \
762 .width = width, \
763 .spec = spec, \
764 .is_long_double = is_long_double, \
765 .is_short = is_short, \
766 .is_long = is_long, \
767 .alt = alt, \
768 .space = space, \
769 .left = left, \
770 .showsign = showsign, \
771 .group = group, \
772 .pad = pad, \
773 .extra = 0, \
774 .i18n = use_outdigits, \
775 .wide = sizeof (CHAR_T) != 1 }; \
777 if (is_long_double) \
778 the_arg.pa_long_double = va_arg (ap, long double); \
779 else \
780 the_arg.pa_double = va_arg (ap, double); \
781 ptr = (const void *) &the_arg; \
783 function_done = __printf_fp (s, &info, &ptr); \
785 else \
787 ptr = (const void *) &args_value[fspec->data_arg]; \
789 function_done = __printf_fp (s, &fspec->info, &ptr); \
792 if (function_done < 0) \
794 /* Error in print handler. */ \
795 done = -1; \
796 goto all_done; \
799 done += function_done; \
801 break; \
803 LABEL (form_floathex): \
805 /* Floating point number printed as hexadecimal number. */ \
806 const void *ptr; \
807 int function_done; \
809 if (fspec == NULL) \
811 struct printf_info info = { .prec = prec, \
812 .width = width, \
813 .spec = spec, \
814 .is_long_double = is_long_double, \
815 .is_short = is_short, \
816 .is_long = is_long, \
817 .alt = alt, \
818 .space = space, \
819 .left = left, \
820 .showsign = showsign, \
821 .group = group, \
822 .pad = pad, \
823 .extra = 0, \
824 .wide = sizeof (CHAR_T) != 1 }; \
826 if (is_long_double) \
827 the_arg.pa_long_double = va_arg (ap, long double); \
828 else \
829 the_arg.pa_double = va_arg (ap, double); \
830 ptr = (const void *) &the_arg; \
832 function_done = __printf_fphex (s, &info, &ptr); \
834 else \
836 ptr = (const void *) &args_value[fspec->data_arg]; \
838 function_done = __printf_fphex (s, &fspec->info, &ptr); \
841 if (function_done < 0) \
843 /* Error in print handler. */ \
844 done = -1; \
845 goto all_done; \
848 done += function_done; \
850 break; \
852 LABEL (form_pointer): \
853 /* Generic pointer. */ \
855 const void *ptr; \
856 if (fspec == NULL) \
857 ptr = va_arg (ap, void *); \
858 else \
859 ptr = args_value[fspec->data_arg].pa_pointer; \
860 if (ptr != NULL) \
862 /* If the pointer is not NULL, write it as a %#x spec. */ \
863 base = 16; \
864 number.word = (unsigned long int) ptr; \
865 is_negative = 0; \
866 alt = 1; \
867 group = 0; \
868 spec = L_('x'); \
869 goto LABEL (number); \
871 else \
873 /* Write "(nil)" for a nil pointer. */ \
874 string = (CHAR_T *) L_("(nil)"); \
875 /* Make sure the full string "(nil)" is printed. */ \
876 if (prec < 5) \
877 prec = 5; \
878 is_long = 0; /* This is no wide-char string. */ \
879 goto LABEL (print_string); \
882 /* NOTREACHED */ \
884 LABEL (form_number): \
885 if (s->_flags2 & _IO_FLAGS2_FORTIFY) \
887 if (! readonly_format) \
889 extern int __readonly_area (const void *, size_t) \
890 attribute_hidden; \
891 readonly_format \
892 = __readonly_area (format, ((STR_LEN (format) + 1) \
893 * sizeof (CHAR_T))); \
895 if (readonly_format < 0) \
896 __libc_fatal ("*** %n in writable segment detected ***\n"); \
898 /* Answer the count of characters written. */ \
899 if (fspec == NULL) \
901 if (is_longlong) \
902 *(long long int *) va_arg (ap, void *) = done; \
903 else if (is_long_num) \
904 *(long int *) va_arg (ap, void *) = done; \
905 else if (is_char) \
906 *(char *) va_arg (ap, void *) = done; \
907 else if (!is_short) \
908 *(int *) va_arg (ap, void *) = done; \
909 else \
910 *(short int *) va_arg (ap, void *) = done; \
912 else \
913 if (is_longlong) \
914 *(long long int *) args_value[fspec->data_arg].pa_pointer = done; \
915 else if (is_long_num) \
916 *(long int *) args_value[fspec->data_arg].pa_pointer = done; \
917 else if (is_char) \
918 *(char *) args_value[fspec->data_arg].pa_pointer = done; \
919 else if (!is_short) \
920 *(int *) args_value[fspec->data_arg].pa_pointer = done; \
921 else \
922 *(short int *) args_value[fspec->data_arg].pa_pointer = done; \
923 break; \
925 LABEL (form_strerror): \
926 /* Print description of error ERRNO. */ \
927 string = \
928 (CHAR_T *) __strerror_r (save_errno, (char *) work_buffer, \
929 sizeof work_buffer); \
930 is_long = 0; /* This is no wide-char string. */ \
931 goto LABEL (print_string)
933 #ifdef COMPILE_WPRINTF
934 # define process_string_arg(fspec) \
935 LABEL (form_character): \
936 /* Character. */ \
937 if (is_long) \
938 goto LABEL (form_wcharacter); \
939 --width; /* Account for the character itself. */ \
940 if (!left) \
941 PAD (L' '); \
942 if (fspec == NULL) \
943 outchar (__btowc ((unsigned char) va_arg (ap, int))); /* Promoted. */ \
944 else \
945 outchar (__btowc ((unsigned char) \
946 args_value[fspec->data_arg].pa_int)); \
947 if (left) \
948 PAD (L' '); \
949 break; \
951 LABEL (form_wcharacter): \
953 /* Wide character. */ \
954 --width; \
955 if (!left) \
956 PAD (L' '); \
957 if (fspec == NULL) \
958 outchar (va_arg (ap, wchar_t)); \
959 else \
960 outchar (args_value[fspec->data_arg].pa_wchar); \
961 if (left) \
962 PAD (L' '); \
964 break; \
966 LABEL (form_string): \
968 size_t len; \
969 int string_malloced; \
971 /* The string argument could in fact be `char *' or `wchar_t *'. \
972 But this should not make a difference here. */ \
973 if (fspec == NULL) \
974 string = (CHAR_T *) va_arg (ap, const wchar_t *); \
975 else \
976 string = (CHAR_T *) args_value[fspec->data_arg].pa_wstring; \
978 /* Entry point for printing other strings. */ \
979 LABEL (print_string): \
981 string_malloced = 0; \
982 if (string == NULL) \
984 /* Write "(null)" if there's space. */ \
985 if (prec == -1 \
986 || prec >= (int) (sizeof (null) / sizeof (null[0])) - 1) \
988 string = (CHAR_T *) null; \
989 len = (sizeof (null) / sizeof (null[0])) - 1; \
991 else \
993 string = (CHAR_T *) L""; \
994 len = 0; \
997 else if (!is_long && spec != L_('S')) \
999 /* This is complicated. We have to transform the multibyte \
1000 string into a wide character string. */ \
1001 const char *mbs = (const char *) string; \
1002 mbstate_t mbstate; \
1004 len = prec != -1 ? (size_t) prec : strlen (mbs); \
1006 /* Allocate dynamically an array which definitely is long \
1007 enough for the wide character version. */ \
1008 if (__libc_use_alloca (len * sizeof (wchar_t))) \
1009 string = (CHAR_T *) alloca (len * sizeof (wchar_t)); \
1010 else if ((string = (CHAR_T *) malloc (len * sizeof (wchar_t))) \
1011 == NULL) \
1013 done = -1; \
1014 goto all_done; \
1016 else \
1017 string_malloced = 1; \
1019 memset (&mbstate, '\0', sizeof (mbstate_t)); \
1020 len = __mbsrtowcs (string, &mbs, len, &mbstate); \
1021 if (len == (size_t) -1) \
1023 /* Illegal multibyte character. */ \
1024 done = -1; \
1025 goto all_done; \
1028 else \
1030 if (prec != -1) \
1031 /* Search for the end of the string, but don't search past \
1032 the length specified by the precision. */ \
1033 len = __wcsnlen (string, prec); \
1034 else \
1035 len = __wcslen (string); \
1038 if ((width -= len) < 0) \
1040 outstring (string, len); \
1041 break; \
1044 if (!left) \
1045 PAD (L' '); \
1046 outstring (string, len); \
1047 if (left) \
1048 PAD (L' '); \
1049 if (__builtin_expect (string_malloced, 0)) \
1050 free (string); \
1052 break;
1053 #else
1054 # define process_string_arg(fspec) \
1055 LABEL (form_character): \
1056 /* Character. */ \
1057 if (is_long) \
1058 goto LABEL (form_wcharacter); \
1059 --width; /* Account for the character itself. */ \
1060 if (!left) \
1061 PAD (' '); \
1062 if (fspec == NULL) \
1063 outchar ((unsigned char) va_arg (ap, int)); /* Promoted. */ \
1064 else \
1065 outchar ((unsigned char) args_value[fspec->data_arg].pa_int); \
1066 if (left) \
1067 PAD (' '); \
1068 break; \
1070 LABEL (form_wcharacter): \
1072 /* Wide character. */ \
1073 char buf[MB_CUR_MAX]; \
1074 mbstate_t mbstate; \
1075 size_t len; \
1077 memset (&mbstate, '\0', sizeof (mbstate_t)); \
1078 len = __wcrtomb (buf, (fspec == NULL ? va_arg (ap, wchar_t) \
1079 : args_value[fspec->data_arg].pa_wchar), \
1080 &mbstate); \
1081 if (len == (size_t) -1) \
1083 /* Something went wron gduring the conversion. Bail out. */ \
1084 done = -1; \
1085 goto all_done; \
1087 width -= len; \
1088 if (!left) \
1089 PAD (' '); \
1090 outstring (buf, len); \
1091 if (left) \
1092 PAD (' '); \
1094 break; \
1096 LABEL (form_string): \
1098 size_t len; \
1099 int string_malloced; \
1101 /* The string argument could in fact be `char *' or `wchar_t *'. \
1102 But this should not make a difference here. */ \
1103 if (fspec == NULL) \
1104 string = (char *) va_arg (ap, const char *); \
1105 else \
1106 string = (char *) args_value[fspec->data_arg].pa_string; \
1108 /* Entry point for printing other strings. */ \
1109 LABEL (print_string): \
1111 string_malloced = 0; \
1112 if (string == NULL) \
1114 /* Write "(null)" if there's space. */ \
1115 if (prec == -1 || prec >= (int) sizeof (null) - 1) \
1117 string = (char *) null; \
1118 len = sizeof (null) - 1; \
1120 else \
1122 string = (char *) ""; \
1123 len = 0; \
1126 else if (!is_long && spec != L_('S')) \
1128 if (prec != -1) \
1130 /* Search for the end of the string, but don't search past \
1131 the length (in bytes) specified by the precision. Also \
1132 don't use incomplete characters. */ \
1133 if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MB_CUR_MAX) == 1) \
1134 len = __strnlen (string, prec); \
1135 else \
1137 /* In case we have a multibyte character set the \
1138 situation is more compilcated. We must not copy \
1139 bytes at the end which form an incomplete character. */\
1140 wchar_t ignore[prec]; \
1141 const char *str2 = string; \
1142 mbstate_t ps; \
1144 memset (&ps, '\0', sizeof (ps)); \
1145 if (__mbsnrtowcs (ignore, &str2, prec, prec, &ps) \
1146 == (size_t) -1) \
1148 done = -1; \
1149 goto all_done; \
1151 if (str2 == NULL) \
1152 len = strlen (string); \
1153 else \
1154 len = str2 - string - (ps.__count & 7); \
1157 else \
1158 len = strlen (string); \
1160 else \
1162 const wchar_t *s2 = (const wchar_t *) string; \
1163 mbstate_t mbstate; \
1165 memset (&mbstate, '\0', sizeof (mbstate_t)); \
1167 if (prec >= 0) \
1169 /* The string `s2' might not be NUL terminated. */ \
1170 if (__libc_use_alloca (prec)) \
1171 string = (char *) alloca (prec); \
1172 else if ((string = (char *) malloc (prec)) == NULL) \
1174 done = -1; \
1175 goto all_done; \
1177 else \
1178 string_malloced = 1; \
1179 len = __wcsrtombs (string, &s2, prec, &mbstate); \
1181 else \
1183 len = __wcsrtombs (NULL, &s2, 0, &mbstate); \
1184 if (len != (size_t) -1) \
1186 assert (__mbsinit (&mbstate)); \
1187 s2 = (const wchar_t *) string; \
1188 if (__libc_use_alloca (len + 1)) \
1189 string = (char *) alloca (len + 1); \
1190 else if ((string = (char *) malloc (len + 1)) == NULL) \
1192 done = -1; \
1193 goto all_done; \
1195 else \
1196 string_malloced = 1; \
1197 (void) __wcsrtombs (string, &s2, len + 1, &mbstate); \
1201 if (len == (size_t) -1) \
1203 /* Illegal wide-character string. */ \
1204 done = -1; \
1205 goto all_done; \
1209 if ((width -= len) < 0) \
1211 outstring (string, len); \
1212 break; \
1215 if (!left) \
1216 PAD (' '); \
1217 outstring (string, len); \
1218 if (left) \
1219 PAD (' '); \
1220 if (__builtin_expect (string_malloced, 0)) \
1221 free (string); \
1223 break;
1224 #endif
1226 /* Orient the stream. */
1227 #ifdef ORIENT
1228 ORIENT;
1229 #endif
1231 /* Sanity check of arguments. */
1232 ARGCHECK (s, format);
1234 #ifdef ORIENT
1235 /* Check for correct orientation. */
1236 if (_IO_vtable_offset (s) == 0 &&
1237 _IO_fwide (s, sizeof (CHAR_T) == 1 ? -1 : 1)
1238 != (sizeof (CHAR_T) == 1 ? -1 : 1))
1239 /* The stream is already oriented otherwise. */
1240 return EOF;
1241 #endif
1243 if (UNBUFFERED_P (s))
1244 /* Use a helper function which will allocate a local temporary buffer
1245 for the stream and then call us again. */
1246 return buffered_vfprintf (s, format, ap);
1248 /* Initialize local variables. */
1249 done = 0;
1250 grouping = (const char *) -1;
1251 #ifdef __va_copy
1252 /* This macro will be available soon in gcc's <stdarg.h>. We need it
1253 since on some systems `va_list' is not an integral type. */
1254 __va_copy (ap_save, ap);
1255 #else
1256 ap_save = ap;
1257 #endif
1258 nspecs_done = 0;
1260 #ifdef COMPILE_WPRINTF
1261 /* Find the first format specifier. */
1262 f = lead_str_end = __find_specwc ((const UCHAR_T *) format);
1263 #else
1264 /* Put state for processing format string in initial state. */
1265 memset (&mbstate, '\0', sizeof (mbstate_t));
1267 /* Find the first format specifier. */
1268 f = lead_str_end = __find_specmb (format, &mbstate);
1269 #endif
1271 /* Lock stream. */
1272 _IO_cleanup_region_start ((void (*) (void *)) &_IO_funlockfile, s);
1273 _IO_flockfile (s);
1275 /* Write the literal text before the first format. */
1276 outstring ((const UCHAR_T *) format,
1277 lead_str_end - (const UCHAR_T *) format);
1279 /* If we only have to print a simple string, return now. */
1280 if (*f == L_('\0'))
1281 goto all_done;
1283 /* Process whole format string. */
1286 #ifdef SHARED
1287 # define REF(Name) &&do_##Name - &&do_form_unknown
1288 #else
1289 # define REF(Name) &&do_##Name
1290 #endif
1291 #define LABEL(Name) do_##Name
1292 STEP0_3_TABLE;
1293 STEP4_TABLE;
1295 union printf_arg *args_value; /* This is not used here but ... */
1296 int is_negative; /* Flag for negative number. */
1297 union
1299 unsigned long long int longlong;
1300 unsigned long int word;
1301 } number;
1302 int base;
1303 union printf_arg the_arg;
1304 CHAR_T *string; /* Pointer to argument string. */
1305 int alt = 0; /* Alternate format. */
1306 int space = 0; /* Use space prefix if no sign is needed. */
1307 int left = 0; /* Left-justify output. */
1308 int showsign = 0; /* Always begin with plus or minus sign. */
1309 int group = 0; /* Print numbers according grouping rules. */
1310 int is_long_double = 0; /* Argument is long double/ long long int. */
1311 int is_short = 0; /* Argument is short int. */
1312 int is_long = 0; /* Argument is long int. */
1313 int is_char = 0; /* Argument is promoted (unsigned) char. */
1314 int width = 0; /* Width of output; 0 means none specified. */
1315 int prec = -1; /* Precision of output; -1 means none specified. */
1316 /* This flag is set by the 'I' modifier and selects the use of the
1317 `outdigits' as determined by the current locale. */
1318 int use_outdigits = 0;
1319 UCHAR_T pad = L_(' ');/* Padding character. */
1320 CHAR_T spec;
1322 workstart = NULL;
1323 workend = &work_buffer[sizeof (work_buffer) / sizeof (CHAR_T)];
1325 /* Get current character in format string. */
1326 JUMP (*++f, step0_jumps);
1328 /* ' ' flag. */
1329 LABEL (flag_space):
1330 space = 1;
1331 JUMP (*++f, step0_jumps);
1333 /* '+' flag. */
1334 LABEL (flag_plus):
1335 showsign = 1;
1336 JUMP (*++f, step0_jumps);
1338 /* The '-' flag. */
1339 LABEL (flag_minus):
1340 left = 1;
1341 pad = L_(' ');
1342 JUMP (*++f, step0_jumps);
1344 /* The '#' flag. */
1345 LABEL (flag_hash):
1346 alt = 1;
1347 JUMP (*++f, step0_jumps);
1349 /* The '0' flag. */
1350 LABEL (flag_zero):
1351 if (!left)
1352 pad = L_('0');
1353 JUMP (*++f, step0_jumps);
1355 /* The '\'' flag. */
1356 LABEL (flag_quote):
1357 group = 1;
1359 if (grouping == (const char *) -1)
1361 #ifdef COMPILE_WPRINTF
1362 thousands_sep = _NL_CURRENT_WORD (LC_NUMERIC,
1363 _NL_NUMERIC_THOUSANDS_SEP_WC);
1364 #else
1365 thousands_sep = _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
1366 #endif
1368 grouping = _NL_CURRENT (LC_NUMERIC, GROUPING);
1369 if (*grouping == '\0' || *grouping == CHAR_MAX
1370 #ifdef COMPILE_WPRINTF
1371 || thousands_sep == L'\0'
1372 #else
1373 || *thousands_sep == '\0'
1374 #endif
1376 grouping = NULL;
1378 JUMP (*++f, step0_jumps);
1380 LABEL (flag_i18n):
1381 use_outdigits = 1;
1382 JUMP (*++f, step0_jumps);
1384 /* Get width from argument. */
1385 LABEL (width_asterics):
1387 const UCHAR_T *tmp; /* Temporary value. */
1389 tmp = ++f;
1390 if (ISDIGIT (*tmp) && read_int (&tmp) && *tmp == L_('$'))
1391 /* The width comes from a positional parameter. */
1392 goto do_positional;
1394 width = va_arg (ap, int);
1396 /* Negative width means left justified. */
1397 if (width < 0)
1399 width = -width;
1400 pad = L_(' ');
1401 left = 1;
1404 if (width + 32 >= (int) (sizeof (work_buffer)
1405 / sizeof (work_buffer[0])))
1407 /* We have to use a special buffer. The "32" is just a safe
1408 bet for all the output which is not counted in the width. */
1409 if (__libc_use_alloca ((width + 32) * sizeof (CHAR_T)))
1410 workend = ((CHAR_T *) alloca ((width + 32) * sizeof (CHAR_T))
1411 + (width + 32));
1412 else
1414 workstart = (CHAR_T *) malloc ((width + 32) * sizeof (CHAR_T));
1415 if (workstart == NULL)
1417 done = -1;
1418 goto all_done;
1420 workend = workstart + (width + 32);
1424 JUMP (*f, step1_jumps);
1426 /* Given width in format string. */
1427 LABEL (width):
1428 width = read_int (&f);
1430 if (width + 32 >= (int) (sizeof (work_buffer) / sizeof (work_buffer[0])))
1432 /* We have to use a special buffer. The "32" is just a safe
1433 bet for all the output which is not counted in the width. */
1434 if (__libc_use_alloca ((width + 32) * sizeof (CHAR_T)))
1435 workend = ((CHAR_T *) alloca ((width + 32) * sizeof (CHAR_T))
1436 + (width + 32));
1437 else
1439 workstart = (CHAR_T *) malloc ((width + 32) * sizeof (CHAR_T));
1440 if (workstart == NULL)
1442 done = -1;
1443 goto all_done;
1445 workend = workstart + (width + 32);
1448 if (*f == L_('$'))
1449 /* Oh, oh. The argument comes from a positional parameter. */
1450 goto do_positional;
1451 JUMP (*f, step1_jumps);
1453 LABEL (precision):
1454 ++f;
1455 if (*f == L_('*'))
1457 const UCHAR_T *tmp; /* Temporary value. */
1459 tmp = ++f;
1460 if (ISDIGIT (*tmp) && read_int (&tmp) > 0 && *tmp == L_('$'))
1461 /* The precision comes from a positional parameter. */
1462 goto do_positional;
1464 prec = va_arg (ap, int);
1466 /* If the precision is negative the precision is omitted. */
1467 if (prec < 0)
1468 prec = -1;
1470 else if (ISDIGIT (*f))
1471 prec = read_int (&f);
1472 else
1473 prec = 0;
1474 if (prec > width
1475 && prec + 32 > (int)(sizeof (work_buffer) / sizeof (work_buffer[0])))
1477 if (__libc_use_alloca ((prec + 32) * sizeof (CHAR_T)))
1478 workend = ((CHAR_T *) alloca ((prec + 32) * sizeof (CHAR_T)))
1479 + (prec + 32);
1480 else
1482 workstart = (CHAR_T *) malloc ((prec + 32) * sizeof (CHAR_T));
1483 if (workstart == NULL)
1485 done = -1;
1486 goto all_done;
1488 workend = workstart + (prec + 32);
1491 JUMP (*f, step2_jumps);
1493 /* Process 'h' modifier. There might another 'h' following. */
1494 LABEL (mod_half):
1495 is_short = 1;
1496 JUMP (*++f, step3a_jumps);
1498 /* Process 'hh' modifier. */
1499 LABEL (mod_halfhalf):
1500 is_short = 0;
1501 is_char = 1;
1502 JUMP (*++f, step4_jumps);
1504 /* Process 'l' modifier. There might another 'l' following. */
1505 LABEL (mod_long):
1506 is_long = 1;
1507 JUMP (*++f, step3b_jumps);
1509 /* Process 'L', 'q', or 'll' modifier. No other modifier is
1510 allowed to follow. */
1511 LABEL (mod_longlong):
1512 is_long_double = 1;
1513 is_long = 1;
1514 JUMP (*++f, step4_jumps);
1516 LABEL (mod_size_t):
1517 is_long_double = sizeof (size_t) > sizeof (unsigned long int);
1518 is_long = sizeof (size_t) > sizeof (unsigned int);
1519 JUMP (*++f, step4_jumps);
1521 LABEL (mod_ptrdiff_t):
1522 is_long_double = sizeof (ptrdiff_t) > sizeof (unsigned long int);
1523 is_long = sizeof (ptrdiff_t) > sizeof (unsigned int);
1524 JUMP (*++f, step4_jumps);
1526 LABEL (mod_intmax_t):
1527 is_long_double = sizeof (intmax_t) > sizeof (unsigned long int);
1528 is_long = sizeof (intmax_t) > sizeof (unsigned int);
1529 JUMP (*++f, step4_jumps);
1531 /* Process current format. */
1532 while (1)
1534 process_arg (((struct printf_spec *) NULL));
1535 process_string_arg (((struct printf_spec *) NULL));
1537 LABEL (form_unknown):
1538 if (spec == L_('\0'))
1540 /* The format string ended before the specifier is complete. */
1541 done = -1;
1542 goto all_done;
1545 /* If we are in the fast loop force entering the complicated
1546 one. */
1547 goto do_positional;
1550 /* The format is correctly handled. */
1551 ++nspecs_done;
1553 if (__builtin_expect (workstart != NULL, 0))
1554 free (workstart);
1555 workstart = NULL;
1557 /* Look for next format specifier. */
1558 #ifdef COMPILE_WPRINTF
1559 f = __find_specwc ((end_of_spec = ++f));
1560 #else
1561 f = __find_specmb ((end_of_spec = ++f), &mbstate);
1562 #endif
1564 /* Write the following constant string. */
1565 outstring (end_of_spec, f - end_of_spec);
1567 while (*f != L_('\0'));
1569 /* Unlock stream and return. */
1570 goto all_done;
1572 /* Here starts the more complex loop to handle positional parameters. */
1573 do_positional:
1575 /* Array with information about the needed arguments. This has to
1576 be dynamically extensible. */
1577 size_t nspecs = 0;
1578 size_t nspecs_max = 32; /* A more or less arbitrary start value. */
1579 struct printf_spec *specs
1580 = alloca (nspecs_max * sizeof (struct printf_spec));
1582 /* The number of arguments the format string requests. This will
1583 determine the size of the array needed to store the argument
1584 attributes. */
1585 size_t nargs = 0;
1586 int *args_type;
1587 union printf_arg *args_value = NULL;
1589 /* Positional parameters refer to arguments directly. This could
1590 also determine the maximum number of arguments. Track the
1591 maximum number. */
1592 size_t max_ref_arg = 0;
1594 /* Just a counter. */
1595 size_t cnt;
1598 if (grouping == (const char *) -1)
1600 #ifdef COMPILE_WPRINTF
1601 thousands_sep = _NL_CURRENT_WORD (LC_NUMERIC,
1602 _NL_NUMERIC_THOUSANDS_SEP_WC);
1603 #else
1604 thousands_sep = _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
1605 #endif
1607 grouping = _NL_CURRENT (LC_NUMERIC, GROUPING);
1608 if (*grouping == '\0' || *grouping == CHAR_MAX)
1609 grouping = NULL;
1612 for (f = lead_str_end; *f != L_('\0'); f = specs[nspecs++].next_fmt)
1614 if (nspecs >= nspecs_max)
1616 /* Extend the array of format specifiers. */
1617 struct printf_spec *old = specs;
1619 nspecs_max *= 2;
1620 specs = alloca (nspecs_max * sizeof (struct printf_spec));
1622 if (specs == &old[nspecs])
1623 /* Stack grows up, OLD was the last thing allocated;
1624 extend it. */
1625 nspecs_max += nspecs_max / 2;
1626 else
1628 /* Copy the old array's elements to the new space. */
1629 memcpy (specs, old, nspecs * sizeof (struct printf_spec));
1630 if (old == &specs[nspecs])
1631 /* Stack grows down, OLD was just below the new
1632 SPECS. We can use that space when the new space
1633 runs out. */
1634 nspecs_max += nspecs_max / 2;
1638 /* Parse the format specifier. */
1639 #ifdef COMPILE_WPRINTF
1640 nargs += __parse_one_specwc (f, nargs, &specs[nspecs], &max_ref_arg);
1641 #else
1642 nargs += __parse_one_specmb (f, nargs, &specs[nspecs], &max_ref_arg,
1643 &mbstate);
1644 #endif
1647 /* Determine the number of arguments the format string consumes. */
1648 nargs = MAX (nargs, max_ref_arg);
1650 /* Allocate memory for the argument descriptions. */
1651 args_type = alloca (nargs * sizeof (int));
1652 memset (args_type, s->_flags2 & _IO_FLAGS2_FORTIFY ? '\xff' : '\0',
1653 nargs * sizeof (int));
1654 args_value = alloca (nargs * sizeof (union printf_arg));
1656 /* XXX Could do sanity check here: If any element in ARGS_TYPE is
1657 still zero after this loop, format is invalid. For now we
1658 simply use 0 as the value. */
1660 /* Fill in the types of all the arguments. */
1661 for (cnt = 0; cnt < nspecs; ++cnt)
1663 /* If the width is determined by an argument this is an int. */
1664 if (specs[cnt].width_arg != -1)
1665 args_type[specs[cnt].width_arg] = PA_INT;
1667 /* If the precision is determined by an argument this is an int. */
1668 if (specs[cnt].prec_arg != -1)
1669 args_type[specs[cnt].prec_arg] = PA_INT;
1671 switch (specs[cnt].ndata_args)
1673 case 0: /* No arguments. */
1674 break;
1675 case 1: /* One argument; we already have the type. */
1676 args_type[specs[cnt].data_arg] = specs[cnt].data_arg_type;
1677 break;
1678 default:
1679 /* We have more than one argument for this format spec.
1680 We must call the arginfo function again to determine
1681 all the types. */
1682 (void) (*__printf_arginfo_table[specs[cnt].info.spec])
1683 (&specs[cnt].info,
1684 specs[cnt].ndata_args, &args_type[specs[cnt].data_arg]);
1685 break;
1689 /* Now we know all the types and the order. Fill in the argument
1690 values. */
1691 for (cnt = 0; cnt < nargs; ++cnt)
1692 switch (args_type[cnt])
1694 #define T(tag, mem, type) \
1695 case tag: \
1696 args_value[cnt].mem = va_arg (ap_save, type); \
1697 break
1699 T (PA_CHAR, pa_int, int); /* Promoted. */
1700 T (PA_WCHAR, pa_wchar, wint_t);
1701 T (PA_INT|PA_FLAG_SHORT, pa_int, int); /* Promoted. */
1702 T (PA_INT, pa_int, int);
1703 T (PA_INT|PA_FLAG_LONG, pa_long_int, long int);
1704 T (PA_INT|PA_FLAG_LONG_LONG, pa_long_long_int, long long int);
1705 T (PA_FLOAT, pa_double, double); /* Promoted. */
1706 T (PA_DOUBLE, pa_double, double);
1707 T (PA_DOUBLE|PA_FLAG_LONG_DOUBLE, pa_long_double, long double);
1708 T (PA_STRING, pa_string, const char *);
1709 T (PA_WSTRING, pa_wstring, const wchar_t *);
1710 T (PA_POINTER, pa_pointer, void *);
1711 #undef T
1712 default:
1713 if ((args_type[cnt] & PA_FLAG_PTR) != 0)
1714 args_value[cnt].pa_pointer = va_arg (ap_save, void *);
1715 else
1716 args_value[cnt].pa_long_double = 0.0;
1717 break;
1718 case -1:
1719 /* Error case. Not all parameters appear in N$ format
1720 strings. We have no way to determine their type. */
1721 assert (s->_flags2 & _IO_FLAGS2_FORTIFY);
1722 __libc_fatal ("*** invalid %N$ use detected ***\n");
1725 /* Now walk through all format specifiers and process them. */
1726 for (; (size_t) nspecs_done < nspecs; ++nspecs_done)
1728 #undef REF
1729 #ifdef SHARED
1730 # define REF(Name) &&do2_##Name - &&do_form_unknown
1731 #else
1732 # define REF(Name) &&do2_##Name
1733 #endif
1734 #undef LABEL
1735 #define LABEL(Name) do2_##Name
1736 STEP4_TABLE;
1738 int is_negative;
1739 union
1741 unsigned long long int longlong;
1742 unsigned long int word;
1743 } number;
1744 int base;
1745 union printf_arg the_arg;
1746 CHAR_T *string; /* Pointer to argument string. */
1748 /* Fill variables from values in struct. */
1749 int alt = specs[nspecs_done].info.alt;
1750 int space = specs[nspecs_done].info.space;
1751 int left = specs[nspecs_done].info.left;
1752 int showsign = specs[nspecs_done].info.showsign;
1753 int group = specs[nspecs_done].info.group;
1754 int is_long_double = specs[nspecs_done].info.is_long_double;
1755 int is_short = specs[nspecs_done].info.is_short;
1756 int is_char = specs[nspecs_done].info.is_char;
1757 int is_long = specs[nspecs_done].info.is_long;
1758 int width = specs[nspecs_done].info.width;
1759 int prec = specs[nspecs_done].info.prec;
1760 int use_outdigits = specs[nspecs_done].info.i18n;
1761 char pad = specs[nspecs_done].info.pad;
1762 CHAR_T spec = specs[nspecs_done].info.spec;
1763 CHAR_T *workstart = NULL;
1765 /* Fill in last information. */
1766 if (specs[nspecs_done].width_arg != -1)
1768 /* Extract the field width from an argument. */
1769 specs[nspecs_done].info.width =
1770 args_value[specs[nspecs_done].width_arg].pa_int;
1772 if (specs[nspecs_done].info.width < 0)
1773 /* If the width value is negative left justification is
1774 selected and the value is taken as being positive. */
1776 specs[nspecs_done].info.width *= -1;
1777 left = specs[nspecs_done].info.left = 1;
1779 width = specs[nspecs_done].info.width;
1782 if (specs[nspecs_done].prec_arg != -1)
1784 /* Extract the precision from an argument. */
1785 specs[nspecs_done].info.prec =
1786 args_value[specs[nspecs_done].prec_arg].pa_int;
1788 if (specs[nspecs_done].info.prec < 0)
1789 /* If the precision is negative the precision is
1790 omitted. */
1791 specs[nspecs_done].info.prec = -1;
1793 prec = specs[nspecs_done].info.prec;
1796 /* Maybe the buffer is too small. */
1797 if (MAX (prec, width) + 32 > (int) (sizeof (work_buffer)
1798 / sizeof (CHAR_T)))
1800 if (__libc_use_alloca ((MAX (prec, width) + 32)
1801 * sizeof (CHAR_T)))
1802 workend = ((CHAR_T *) alloca ((MAX (prec, width) + 32)
1803 * sizeof (CHAR_T))
1804 + (MAX (prec, width) + 32));
1805 else
1807 workstart = (CHAR_T *) malloc ((MAX (prec, width) + 32)
1808 * sizeof (CHAR_T));
1809 workend = workstart + (MAX (prec, width) + 32);
1813 /* Process format specifiers. */
1814 while (1)
1816 JUMP (spec, step4_jumps);
1818 process_arg ((&specs[nspecs_done]));
1819 process_string_arg ((&specs[nspecs_done]));
1821 LABEL (form_unknown):
1823 extern printf_function **__printf_function_table;
1824 int function_done;
1825 printf_function *function;
1826 unsigned int i;
1827 const void **ptr;
1829 function =
1830 (__printf_function_table == NULL ? NULL :
1831 __printf_function_table[specs[nspecs_done].info.spec]);
1833 if (function == NULL)
1834 function = &printf_unknown;
1836 ptr = alloca (specs[nspecs_done].ndata_args
1837 * sizeof (const void *));
1839 /* Fill in an array of pointers to the argument values. */
1840 for (i = 0; i < specs[nspecs_done].ndata_args; ++i)
1841 ptr[i] = &args_value[specs[nspecs_done].data_arg + i];
1843 /* Call the function. */
1844 function_done = (*function) (s, &specs[nspecs_done].info, ptr);
1846 /* If an error occurred we don't have information about #
1847 of chars. */
1848 if (function_done < 0)
1850 done = -1;
1851 goto all_done;
1854 done += function_done;
1856 break;
1859 if (__builtin_expect (workstart != NULL, 0))
1860 free (workstart);
1861 workstart = NULL;
1863 /* Write the following constant string. */
1864 outstring (specs[nspecs_done].end_of_fmt,
1865 specs[nspecs_done].next_fmt
1866 - specs[nspecs_done].end_of_fmt);
1870 all_done:
1871 if (__builtin_expect (workstart != NULL, 0))
1872 free (workstart);
1873 /* Unlock the stream. */
1874 _IO_funlockfile (s);
1875 _IO_cleanup_region_end (0);
1877 return done;
1880 /* Handle an unknown format specifier. This prints out a canonicalized
1881 representation of the format spec itself. */
1882 static int
1883 printf_unknown (FILE *s, const struct printf_info *info,
1884 const void *const *args)
1887 int done = 0;
1888 CHAR_T work_buffer[MAX (info->width, info->spec) + 32];
1889 CHAR_T *const workend
1890 = &work_buffer[sizeof (work_buffer) / sizeof (CHAR_T)];
1891 register CHAR_T *w;
1893 outchar (L_('%'));
1895 if (info->alt)
1896 outchar (L_('#'));
1897 if (info->group)
1898 outchar (L_('\''));
1899 if (info->showsign)
1900 outchar (L_('+'));
1901 else if (info->space)
1902 outchar (L_(' '));
1903 if (info->left)
1904 outchar (L_('-'));
1905 if (info->pad == L_('0'))
1906 outchar (L_('0'));
1907 if (info->i18n)
1908 outchar (L_('I'));
1910 if (info->width != 0)
1912 w = _itoa_word (info->width, workend, 10, 0);
1913 while (w < workend)
1914 outchar (*w++);
1917 if (info->prec != -1)
1919 outchar (L_('.'));
1920 w = _itoa_word (info->prec, workend, 10, 0);
1921 while (w < workend)
1922 outchar (*w++);
1925 if (info->spec != L_('\0'))
1926 outchar (info->spec);
1928 all_done:
1929 return done;
1932 /* Group the digits according to the grouping rules of the current locale.
1933 The interpretation of GROUPING is as in `struct lconv' from <locale.h>. */
1934 static CHAR_T *
1935 internal_function
1936 group_number (CHAR_T *w, CHAR_T *rear_ptr, const char *grouping,
1937 #ifdef COMPILE_WPRINTF
1938 wchar_t thousands_sep
1939 #else
1940 const char *thousands_sep
1941 #endif
1944 int len;
1945 CHAR_T *src, *s;
1946 #ifndef COMPILE_WPRINTF
1947 int tlen = strlen (thousands_sep);
1948 #endif
1950 /* We treat all negative values like CHAR_MAX. */
1952 if (*grouping == CHAR_MAX || *grouping <= 0)
1953 /* No grouping should be done. */
1954 return w;
1956 len = *grouping++;
1958 /* Copy existing string so that nothing gets overwritten. */
1959 src = (CHAR_T *) alloca ((rear_ptr - w) * sizeof (CHAR_T));
1960 s = (CHAR_T *) __mempcpy (src, w,
1961 (rear_ptr - w) * sizeof (CHAR_T));
1962 w = rear_ptr;
1964 /* Process all characters in the string. */
1965 while (s > src)
1967 *--w = *--s;
1969 if (--len == 0 && s > src)
1971 /* A new group begins. */
1972 #ifdef COMPILE_WPRINTF
1973 *--w = thousands_sep;
1974 #else
1975 int cnt = tlen;
1977 *--w = thousands_sep[--cnt];
1978 while (cnt > 0);
1979 #endif
1981 if (*grouping == CHAR_MAX
1982 #if CHAR_MIN < 0
1983 || *grouping < 0
1984 #endif
1987 /* No further grouping to be done.
1988 Copy the rest of the number. */
1990 *--w = *--s;
1991 while (s > src);
1992 break;
1994 else if (*grouping != '\0')
1995 /* The previous grouping repeats ad infinitum. */
1996 len = *grouping++;
1997 else
1998 len = grouping[-1];
2001 return w;
2004 /* Helper "class" for `fprintf to unbuffered': creates a temporary buffer. */
2005 struct helper_file
2007 struct _IO_FILE_plus _f;
2008 #ifdef COMPILE_WPRINTF
2009 struct _IO_wide_data _wide_data;
2010 #endif
2011 _IO_FILE *_put_stream;
2012 #ifdef _IO_MTSAFE_IO
2013 _IO_lock_t lock;
2014 #endif
2017 static int
2018 _IO_helper_overflow (_IO_FILE *s, int c)
2020 _IO_FILE *target = ((struct helper_file*) s)->_put_stream;
2021 #ifdef COMPILE_WPRINTF
2022 int used = s->_wide_data->_IO_write_ptr - s->_wide_data->_IO_write_base;
2023 if (used)
2025 _IO_size_t written = _IO_sputn (target, s->_wide_data->_IO_write_base,
2026 used);
2027 s->_wide_data->_IO_write_ptr -= written;
2029 #else
2030 int used = s->_IO_write_ptr - s->_IO_write_base;
2031 if (used)
2033 _IO_size_t written = _IO_sputn (target, s->_IO_write_base, used);
2034 s->_IO_write_ptr -= written;
2036 #endif
2037 return PUTC (c, s);
2040 #ifdef COMPILE_WPRINTF
2041 static const struct _IO_jump_t _IO_helper_jumps =
2043 JUMP_INIT_DUMMY,
2044 JUMP_INIT (finish, INTUSE(_IO_wdefault_finish)),
2045 JUMP_INIT (overflow, _IO_helper_overflow),
2046 JUMP_INIT (underflow, _IO_default_underflow),
2047 JUMP_INIT (uflow, INTUSE(_IO_default_uflow)),
2048 JUMP_INIT (pbackfail, (_IO_pbackfail_t) INTUSE(_IO_wdefault_pbackfail)),
2049 JUMP_INIT (xsputn, INTUSE(_IO_wdefault_xsputn)),
2050 JUMP_INIT (xsgetn, INTUSE(_IO_wdefault_xsgetn)),
2051 JUMP_INIT (seekoff, _IO_default_seekoff),
2052 JUMP_INIT (seekpos, _IO_default_seekpos),
2053 JUMP_INIT (setbuf, _IO_default_setbuf),
2054 JUMP_INIT (sync, _IO_default_sync),
2055 JUMP_INIT (doallocate, INTUSE(_IO_wdefault_doallocate)),
2056 JUMP_INIT (read, _IO_default_read),
2057 JUMP_INIT (write, _IO_default_write),
2058 JUMP_INIT (seek, _IO_default_seek),
2059 JUMP_INIT (close, _IO_default_close),
2060 JUMP_INIT (stat, _IO_default_stat)
2062 #else
2063 static const struct _IO_jump_t _IO_helper_jumps =
2065 JUMP_INIT_DUMMY,
2066 JUMP_INIT (finish, INTUSE(_IO_default_finish)),
2067 JUMP_INIT (overflow, _IO_helper_overflow),
2068 JUMP_INIT (underflow, _IO_default_underflow),
2069 JUMP_INIT (uflow, INTUSE(_IO_default_uflow)),
2070 JUMP_INIT (pbackfail, INTUSE(_IO_default_pbackfail)),
2071 JUMP_INIT (xsputn, INTUSE(_IO_default_xsputn)),
2072 JUMP_INIT (xsgetn, INTUSE(_IO_default_xsgetn)),
2073 JUMP_INIT (seekoff, _IO_default_seekoff),
2074 JUMP_INIT (seekpos, _IO_default_seekpos),
2075 JUMP_INIT (setbuf, _IO_default_setbuf),
2076 JUMP_INIT (sync, _IO_default_sync),
2077 JUMP_INIT (doallocate, INTUSE(_IO_default_doallocate)),
2078 JUMP_INIT (read, _IO_default_read),
2079 JUMP_INIT (write, _IO_default_write),
2080 JUMP_INIT (seek, _IO_default_seek),
2081 JUMP_INIT (close, _IO_default_close),
2082 JUMP_INIT (stat, _IO_default_stat)
2084 #endif
2086 static int
2087 internal_function
2088 buffered_vfprintf (register _IO_FILE *s, const CHAR_T *format,
2089 _IO_va_list args)
2091 CHAR_T buf[_IO_BUFSIZ];
2092 struct helper_file helper;
2093 register _IO_FILE *hp = (_IO_FILE *) &helper._f;
2094 int result, to_flush;
2096 /* Orient the stream. */
2097 #ifdef ORIENT
2098 ORIENT;
2099 #endif
2101 /* Initialize helper. */
2102 helper._put_stream = s;
2103 #ifdef COMPILE_WPRINTF
2104 hp->_wide_data = &helper._wide_data;
2105 _IO_wsetp (hp, buf, buf + sizeof buf / sizeof (CHAR_T));
2106 hp->_mode = 1;
2107 #else
2108 _IO_setp (hp, buf, buf + sizeof buf);
2109 hp->_mode = -1;
2110 #endif
2111 hp->_IO_file_flags = _IO_MAGIC|_IO_NO_READS|_IO_USER_LOCK;
2112 #if _IO_JUMPS_OFFSET
2113 hp->_vtable_offset = 0;
2114 #endif
2115 #ifdef _IO_MTSAFE_IO
2116 hp->_lock = NULL;
2117 #endif
2118 hp->_flags2 = s->_flags2;
2119 _IO_JUMPS (&helper._f) = (struct _IO_jump_t *) &_IO_helper_jumps;
2121 /* Now print to helper instead. */
2122 #ifndef COMPILE_WPRINTF
2123 result = INTUSE(_IO_vfprintf) (hp, format, args);
2124 #else
2125 result = vfprintf (hp, format, args);
2126 #endif
2128 /* Lock stream. */
2129 __libc_cleanup_region_start (1, (void (*) (void *)) &_IO_funlockfile, s);
2130 _IO_flockfile (s);
2132 /* Now flush anything from the helper to the S. */
2133 #ifdef COMPILE_WPRINTF
2134 if ((to_flush = (hp->_wide_data->_IO_write_ptr
2135 - hp->_wide_data->_IO_write_base)) > 0)
2137 if ((int) _IO_sputn (s, hp->_wide_data->_IO_write_base, to_flush)
2138 != to_flush)
2139 result = -1;
2141 #else
2142 if ((to_flush = hp->_IO_write_ptr - hp->_IO_write_base) > 0)
2144 if ((int) _IO_sputn (s, hp->_IO_write_base, to_flush) != to_flush)
2145 result = -1;
2147 #endif
2149 /* Unlock the stream. */
2150 _IO_funlockfile (s);
2151 __libc_cleanup_region_end (0);
2153 return result;
2156 #undef vfprintf
2157 #ifdef strong_alias
2158 /* This is for glibc. */
2159 # ifdef COMPILE_WPRINTF
2160 strong_alias (_IO_vfwprintf, __vfwprintf);
2161 weak_alias (_IO_vfwprintf, vfwprintf);
2162 # else
2163 strong_alias (_IO_vfprintf, vfprintf);
2164 libc_hidden_def (vfprintf)
2165 INTDEF(_IO_vfprintf)
2166 # endif
2167 #else
2168 # if defined __ELF__ || defined __GNU_LIBRARY__
2169 # include <gnu-stabs.h>
2170 # ifdef weak_alias
2171 # ifdef COMPILE_WPRINTF
2172 weak_alias (_IO_vfwprintf, vfwprintf);
2173 # else
2174 weak_alias (_IO_vfprintf, vfprintf);
2175 # endif
2176 # endif
2177 # endif
2178 #endif