1 /* Copyright (C) 1991,92,93,94,95,96,97,98 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
27 #include <bits/libc-lock.h>
28 #include <sys/param.h>
30 #include <locale/localeinfo.h>
32 /* This code is shared between the standard stdio implementation found
33 in GNU C library and the libio implementation originally found in
36 Beside this it is also shared between the normal and wide character
37 implementation as defined in ISO/IEC 9899:1990/Amendment 1:1995. */
39 #ifndef COMPILE_WPRINTF
41 # define UCHAR_T unsigned char
44 # define ISDIGIT(Ch) isdigit (Ch)
47 # define PUT(F, S, N) _IO_sputn ((F), (S), (N))
48 # define PAD(Padchar) \
50 done += _IO_padn (s, (Padchar), width)
52 # define PUTC(C, F) putc (C, F)
53 ssize_t __printf_pad
__P ((FILE *, char pad
, size_t n
));
54 # define PAD(Padchar) \
56 { ssize_t __res = __printf_pad (s, (Padchar), width); \
57 if (__res == -1) return -1; \
61 # define vfprintf vfwprintf
62 # define CHAR_T wchar_t
63 # define UCHAR_T uwchar_t
65 # define L_(Str) L##Str
66 # define ISDIGIT(Ch) iswdigit (Ch)
69 # define PUT(F, S, N) _IO_sputn ((F), (S), (N))
70 # define PAD(Padchar) \
72 done += _IO_wpadn (s, (Padchar), width)
74 # define PUTC(C, F) wputc (C, F)
75 ssize_t __wprintf_pad
__P ((FILE *, wchar_t pad
, size_t n
));
76 # define PAD(Padchar) \
78 { ssize_t __res = __wprintf_pad (s, (Padchar), width); \
79 if (__res == -1) return -1; \
84 /* Include the shared code for parsing the format string. */
85 #include "printf-parse.h"
89 /* This code is for use in libio. */
91 # define PUTC(C, F) _IO_putc_unlocked (C, F)
92 # define vfprintf _IO_vfprintf
93 # define FILE _IO_FILE
95 # define va_list _IO_va_list
97 # define BUFSIZ _IO_BUFSIZ
98 # define ARGCHECK(S, Format) \
101 /* Check file argument for consistence. */ \
102 CHECK_FILE (S, -1); \
103 if (S->_flags & _IO_NO_WRITES) \
105 __set_errno (EBADF); \
108 if (Format == NULL) \
114 # define UNBUFFERED_P(S) ((S)->_IO_file_flags & _IO_UNBUFFERED)
115 #else /* ! USE_IN_LIBIO */
116 /* This code is for use in the GNU C library. */
118 # define PUT(F, S, N) fwrite (S, 1, N, F)
119 # define ARGCHECK(S, Format) \
122 /* Check file argument for consistence. */ \
123 if (!__validfp (S) || !S->__mode.__write) \
125 __set_errno (EBADF); \
128 if (Format == NULL) \
130 __set_errno (EINVAL); \
135 if (__flshfp (S, EOF) == EOF) \
140 # define UNBUFFERED_P(s) ((s)->__buffer == NULL)
142 /* XXX These declarations should go as soon as the stdio header files
143 have these prototypes. */
144 extern void __flockfile (FILE *);
145 extern void __funlockfile (FILE *);
146 #endif /* USE_IN_LIBIO */
149 #define outchar(Ch) \
152 register const int outc = (Ch); \
153 if (PUTC (outc, s) == EOF) \
160 #define outstring(String, Len) \
163 if ((size_t) PUT (s, (String), (Len)) != (size_t) (Len)) \
169 /* For handling long_double and longlong we use the same flag. */
171 # define is_longlong is_long_double
175 /* Global variables. */
176 static const char null
[] = "(null)";
179 /* Helper function to provide temporary buffering for unbuffered streams. */
180 static int buffered_vfprintf
__P ((FILE *stream
, const CHAR_T
*fmt
, va_list))
183 /* Handle unknown format specifier. */
184 static int printf_unknown
__P ((FILE *, const struct printf_info
*,
185 const void *const *));
187 /* Group digits of number string. */
188 static char *group_number
__P ((CHAR_T
*, CHAR_T
*, const CHAR_T
*, wchar_t))
192 /* The function itself. */
194 vfprintf (FILE *s
, const CHAR_T
*format
, va_list ap
)
196 /* The character used as thousands separator. */
197 wchar_t thousands_sep
;
199 /* The string describing the size of groups of digits. */
200 const char *grouping
;
202 /* Place to accumulate the result. */
205 /* Current character in format string. */
208 /* End of leading constant string. */
209 const UCHAR_T
*lead_str_end
;
211 /* Points to next format specifier. */
212 const UCHAR_T
*end_of_spec
;
214 /* Buffer intermediate results. */
215 char work_buffer
[1000];
216 #define workend (&work_buffer[sizeof (work_buffer) - 1])
218 /* State for restartable multibyte character handling functions. */
221 /* We have to save the original argument pointer. */
224 /* Count number of specifiers we already processed. */
227 /* For the %m format we may need the current `errno' value. */
228 int save_errno
= errno
;
231 /* This table maps a character into a number representing a
232 class. In each step there is a destination label for each
234 static const int jump_table
[] =
236 /* ' ' */ 1, 0, 0, /* '#' */ 4,
237 0, /* '%' */ 14, 0, /* '\''*/ 6,
238 0, 0, /* '*' */ 7, /* '+' */ 2,
239 0, /* '-' */ 3, /* '.' */ 9, 0,
240 /* '0' */ 5, /* '1' */ 8, /* '2' */ 8, /* '3' */ 8,
241 /* '4' */ 8, /* '5' */ 8, /* '6' */ 8, /* '7' */ 8,
242 /* '8' */ 8, /* '9' */ 8, 0, 0,
244 0, /* 'A' */ 26, 0, /* 'C' */ 25,
245 0, /* 'E' */ 19, 0, /* 'G' */ 19,
247 /* 'L' */ 12, 0, 0, 0,
248 0, 0, 0, /* 'S' */ 21,
250 /* 'X' */ 18, 0, /* 'Z' */ 13, 0,
252 0, /* 'a' */ 26, 0, /* 'c' */ 20,
253 /* 'd' */ 15, /* 'e' */ 19, /* 'f' */ 19, /* 'g' */ 19,
254 /* 'h' */ 10, /* 'i' */ 15, /* 'j' */ 28, 0,
255 /* 'l' */ 11, /* 'm' */ 24, /* 'n' */ 23, /* 'o' */ 17,
256 /* 'p' */ 22, /* 'q' */ 12, 0, /* 's' */ 21,
257 /* 't' */ 27, /* 'u' */ 16, 0, 0,
258 /* 'x' */ 18, 0, /* 'z' */ 13
261 #define NOT_IN_JUMP_RANGE(Ch) ((Ch) < ' ' || (Ch) > 'z')
262 #define CHAR_CLASS(Ch) (jump_table[(int) (Ch) - ' '])
263 #define JUMP(ChExpr, table) \
268 ptr = NOT_IN_JUMP_RANGE (spec) ? REF (form_unknown) \
269 : table[CHAR_CLASS (spec)]; \
274 #define STEP0_3_TABLE \
275 /* Step 0: at the beginning. */ \
276 static const void *step0_jumps[29] = \
278 REF (form_unknown), \
279 REF (flag_space), /* for ' ' */ \
280 REF (flag_plus), /* for '+' */ \
281 REF (flag_minus), /* for '-' */ \
282 REF (flag_hash), /* for '<hash>' */ \
283 REF (flag_zero), /* for '0' */ \
284 REF (flag_quote), /* for '\'' */ \
285 REF (width_asterics), /* for '*' */ \
286 REF (width), /* for '1'...'9' */ \
287 REF (precision), /* for '.' */ \
288 REF (mod_half), /* for 'h' */ \
289 REF (mod_long), /* for 'l' */ \
290 REF (mod_longlong), /* for 'L', 'q' */ \
291 REF (mod_size_t), /* for 'z', 'Z' */ \
292 REF (form_percent), /* for '%' */ \
293 REF (form_integer), /* for 'd', 'i' */ \
294 REF (form_unsigned), /* for 'u' */ \
295 REF (form_octal), /* for 'o' */ \
296 REF (form_hexa), /* for 'X', 'x' */ \
297 REF (form_float), /* for 'E', 'e', 'f', 'G', 'g' */ \
298 REF (form_character), /* for 'c' */ \
299 REF (form_string), /* for 's', 'S' */ \
300 REF (form_pointer), /* for 'p' */ \
301 REF (form_number), /* for 'n' */ \
302 REF (form_strerror), /* for 'm' */ \
303 REF (form_wcharacter), /* for 'C' */ \
304 REF (form_floathex), /* for 'A', 'a' */ \
305 REF (mod_ptrdiff_t), /* for 't' */ \
306 REF (mod_intmax_t), /* for 'j' */ \
308 /* Step 1: after processing width. */ \
309 static const void *step1_jumps[29] = \
311 REF (form_unknown), \
312 REF (form_unknown), /* for ' ' */ \
313 REF (form_unknown), /* for '+' */ \
314 REF (form_unknown), /* for '-' */ \
315 REF (form_unknown), /* for '<hash>' */ \
316 REF (form_unknown), /* for '0' */ \
317 REF (form_unknown), /* for '\'' */ \
318 REF (form_unknown), /* for '*' */ \
319 REF (form_unknown), /* for '1'...'9' */ \
320 REF (precision), /* for '.' */ \
321 REF (mod_half), /* for 'h' */ \
322 REF (mod_long), /* for 'l' */ \
323 REF (mod_longlong), /* for 'L', 'q' */ \
324 REF (mod_size_t), /* for 'z', 'Z' */ \
325 REF (form_percent), /* for '%' */ \
326 REF (form_integer), /* for 'd', 'i' */ \
327 REF (form_unsigned), /* for 'u' */ \
328 REF (form_octal), /* for 'o' */ \
329 REF (form_hexa), /* for 'X', 'x' */ \
330 REF (form_float), /* for 'E', 'e', 'f', 'G', 'g' */ \
331 REF (form_character), /* for 'c' */ \
332 REF (form_string), /* for 's', 'S' */ \
333 REF (form_pointer), /* for 'p' */ \
334 REF (form_number), /* for 'n' */ \
335 REF (form_strerror), /* for 'm' */ \
336 REF (form_wcharacter), /* for 'C' */ \
337 REF (form_floathex), /* for 'A', 'a' */ \
338 REF (mod_ptrdiff_t), /* for 't' */ \
339 REF (mod_intmax_t) /* for 'j' */ \
341 /* Step 2: after processing precision. */ \
342 static const void *step2_jumps[29] = \
344 REF (form_unknown), \
345 REF (form_unknown), /* for ' ' */ \
346 REF (form_unknown), /* for '+' */ \
347 REF (form_unknown), /* for '-' */ \
348 REF (form_unknown), /* for '<hash>' */ \
349 REF (form_unknown), /* for '0' */ \
350 REF (form_unknown), /* for '\'' */ \
351 REF (form_unknown), /* for '*' */ \
352 REF (form_unknown), /* for '1'...'9' */ \
353 REF (form_unknown), /* for '.' */ \
354 REF (mod_half), /* for 'h' */ \
355 REF (mod_long), /* for 'l' */ \
356 REF (mod_longlong), /* for 'L', 'q' */ \
357 REF (mod_size_t), /* for 'z', 'Z' */ \
358 REF (form_percent), /* for '%' */ \
359 REF (form_integer), /* for 'd', 'i' */ \
360 REF (form_unsigned), /* for 'u' */ \
361 REF (form_octal), /* for 'o' */ \
362 REF (form_hexa), /* for 'X', 'x' */ \
363 REF (form_float), /* for 'E', 'e', 'f', 'G', 'g' */ \
364 REF (form_character), /* for 'c' */ \
365 REF (form_string), /* for 's', 'S' */ \
366 REF (form_pointer), /* for 'p' */ \
367 REF (form_number), /* for 'n' */ \
368 REF (form_strerror), /* for 'm' */ \
369 REF (form_wcharacter), /* for 'C' */ \
370 REF (form_floathex), /* for 'A', 'a' */ \
371 REF (mod_ptrdiff_t), /* for 't' */ \
372 REF (mod_intmax_t) /* for 'j' */ \
374 /* Step 3a: after processing first 'h' modifier. */ \
375 static const void *step3a_jumps[29] = \
377 REF (form_unknown), \
378 REF (form_unknown), /* for ' ' */ \
379 REF (form_unknown), /* for '+' */ \
380 REF (form_unknown), /* for '-' */ \
381 REF (form_unknown), /* for '<hash>' */ \
382 REF (form_unknown), /* for '0' */ \
383 REF (form_unknown), /* for '\'' */ \
384 REF (form_unknown), /* for '*' */ \
385 REF (form_unknown), /* for '1'...'9' */ \
386 REF (form_unknown), /* for '.' */ \
387 REF (mod_halfhalf), /* for 'h' */ \
388 REF (form_unknown), /* for 'l' */ \
389 REF (form_unknown), /* for 'L', 'q' */ \
390 REF (form_unknown), /* for 'z', 'Z' */ \
391 REF (form_percent), /* for '%' */ \
392 REF (form_integer), /* for 'd', 'i' */ \
393 REF (form_unsigned), /* for 'u' */ \
394 REF (form_octal), /* for 'o' */ \
395 REF (form_hexa), /* for 'X', 'x' */ \
396 REF (form_unknown), /* for 'E', 'e', 'f', 'G', 'g' */ \
397 REF (form_unknown), /* for 'c' */ \
398 REF (form_unknown), /* for 's', 'S' */ \
399 REF (form_unknown), /* for 'p' */ \
400 REF (form_number), /* for 'n' */ \
401 REF (form_unknown), /* for 'm' */ \
402 REF (form_unknown), /* for 'C' */ \
403 REF (form_unknown), /* for 'A', 'a' */ \
404 REF (form_unknown), /* for 't' */ \
405 REF (form_unknown) /* for 'j' */ \
407 /* Step 3b: after processing first 'l' modifier. */ \
408 static const void *step3b_jumps[29] = \
410 REF (form_unknown), \
411 REF (form_unknown), /* for ' ' */ \
412 REF (form_unknown), /* for '+' */ \
413 REF (form_unknown), /* for '-' */ \
414 REF (form_unknown), /* for '<hash>' */ \
415 REF (form_unknown), /* for '0' */ \
416 REF (form_unknown), /* for '\'' */ \
417 REF (form_unknown), /* for '*' */ \
418 REF (form_unknown), /* for '1'...'9' */ \
419 REF (form_unknown), /* for '.' */ \
420 REF (form_unknown), /* for 'h' */ \
421 REF (mod_longlong), /* for 'l' */ \
422 REF (form_unknown), /* for 'L', 'q' */ \
423 REF (form_unknown), /* for 'z', 'Z' */ \
424 REF (form_percent), /* for '%' */ \
425 REF (form_integer), /* for 'd', 'i' */ \
426 REF (form_unsigned), /* for 'u' */ \
427 REF (form_octal), /* for 'o' */ \
428 REF (form_hexa), /* for 'X', 'x' */ \
429 REF (form_float), /* for 'E', 'e', 'f', 'G', 'g' */ \
430 REF (form_character), /* for 'c' */ \
431 REF (form_string), /* for 's', 'S' */ \
432 REF (form_pointer), /* for 'p' */ \
433 REF (form_number), /* for 'n' */ \
434 REF (form_strerror), /* for 'm' */ \
435 REF (form_wcharacter), /* for 'C' */ \
436 REF (form_floathex), /* for 'A', 'a' */ \
437 REF (form_unknown), /* for 't' */ \
438 REF (form_unknown) /* for 'j' */ \
441 #define STEP4_TABLE \
442 /* Step 4: processing format specifier. */ \
443 static const void *step4_jumps[29] = \
445 REF (form_unknown), \
446 REF (form_unknown), /* for ' ' */ \
447 REF (form_unknown), /* for '+' */ \
448 REF (form_unknown), /* for '-' */ \
449 REF (form_unknown), /* for '<hash>' */ \
450 REF (form_unknown), /* for '0' */ \
451 REF (form_unknown), /* for '\'' */ \
452 REF (form_unknown), /* for '*' */ \
453 REF (form_unknown), /* for '1'...'9' */ \
454 REF (form_unknown), /* for '.' */ \
455 REF (form_unknown), /* for 'h' */ \
456 REF (form_unknown), /* for 'l' */ \
457 REF (form_unknown), /* for 'L', 'q' */ \
458 REF (form_unknown), /* for 'z', 'Z' */ \
459 REF (form_percent), /* for '%' */ \
460 REF (form_integer), /* for 'd', 'i' */ \
461 REF (form_unsigned), /* for 'u' */ \
462 REF (form_octal), /* for 'o' */ \
463 REF (form_hexa), /* for 'X', 'x' */ \
464 REF (form_float), /* for 'E', 'e', 'f', 'G', 'g' */ \
465 REF (form_character), /* for 'c' */ \
466 REF (form_string), /* for 's', 'S' */ \
467 REF (form_pointer), /* for 'p' */ \
468 REF (form_number), /* for 'n' */ \
469 REF (form_strerror), /* for 'm' */ \
470 REF (form_wcharacter), /* for 'C' */ \
471 REF (form_floathex), /* for 'A', 'a' */ \
472 REF (form_unknown), /* for 't' */ \
473 REF (form_unknown) /* for 'j' */ \
477 #define process_arg(fspec) \
478 /* Start real work. We know about all flags and modifiers and \
479 now process the wanted format specifier. */ \
480 LABEL (form_percent): \
481 /* Write a literal "%". */ \
485 LABEL (form_integer): \
486 /* Signed decimal integer. */ \
491 long long int signed_number; \
494 signed_number = va_arg (ap, long long int); \
496 signed_number = args_value[fspec->data_arg].pa_long_long_int; \
498 is_negative = signed_number < 0; \
499 number.longlong = is_negative ? (- signed_number) : signed_number; \
501 goto LABEL (longlong_number); \
505 long int signed_number; \
510 signed_number = va_arg (ap, long int); \
511 else /* `char' and `short int' will be promoted to `int'. */ \
512 signed_number = va_arg (ap, int); \
516 signed_number = args_value[fspec->data_arg].pa_long_int; \
518 signed_number = args_value[fspec->data_arg].pa_int; \
520 is_negative = signed_number < 0; \
521 number.word = is_negative ? (- signed_number) : signed_number; \
523 goto LABEL (number); \
527 LABEL (form_unsigned): \
528 /* Unsigned decimal integer. */ \
530 goto LABEL (unsigned_number); \
533 LABEL (form_octal): \
534 /* Unsigned octal integer. */ \
536 goto LABEL (unsigned_number); \
540 /* Unsigned hexadecimal integer. */ \
543 LABEL (unsigned_number): /* Unsigned number of base BASE. */ \
545 /* ISO specifies the `+' and ` ' flags only for signed \
554 number.longlong = va_arg (ap, unsigned long long int); \
556 number.longlong = args_value[fspec->data_arg].pa_u_long_long_int; \
558 LABEL (longlong_number): \
560 /* Supply a default precision if none was given. */ \
563 /* We have to take care for the '0' flag. If a precision \
564 is given it must be ignored. */ \
567 /* If the precision is 0 and the number is 0 nothing has to \
568 be written for the number, except for the 'o' format in \
570 if (prec == 0 && number.longlong == 0) \
573 if (base == 8 && alt) \
578 /* Put the number in WORK. */ \
579 string = _itoa (number.longlong, workend + 1, base, \
582 if (group && grouping) \
583 string = group_number (string, workend, grouping, \
586 /* Simply further test for num != 0. */ \
587 number.word = number.longlong != 0; \
594 number.word = va_arg (ap, unsigned long int); \
595 else if (!is_short) \
596 number.word = va_arg (ap, unsigned int); \
598 number.word = (unsigned short int) va_arg (ap, unsigned int); \
602 number.word = args_value[fspec->data_arg].pa_u_long_int; \
604 number.word = (unsigned char) \
605 args_value[fspec->data_arg].pa_char; \
606 else if (!is_short) \
607 number.word = args_value[fspec->data_arg].pa_u_int; \
609 number.word = (unsigned short int) \
610 args_value[fspec->data_arg].pa_u_short_int; \
614 /* Supply a default precision if none was given. */ \
617 /* We have to take care for the '0' flag. If a precision \
618 is given it must be ignored. */ \
621 /* If the precision is 0 and the number is 0 nothing has to \
622 be written for the number, except for the 'o' format in \
624 if (prec == 0 && number.word == 0) \
627 if (base == 8 && alt) \
632 /* Put the number in WORK. */ \
633 string = _itoa_word (number.word, workend + 1, base, \
636 if (group && grouping) \
637 string = group_number (string, workend, grouping, \
642 prec -= workend - string; \
645 /* Add zeros to the precision. */ \
648 else if (number.word != 0 && alt && base == 8) \
649 /* Add octal marker. */ \
654 width -= workend - string; \
656 if (number.word != 0 && alt && base == 16) \
657 /* Account for 0X hex marker. */ \
660 if (is_negative || showsign || space) \
665 while (width-- > 0) \
668 if (number.word != 0 && alt && base == 16) \
683 if (number.word != 0 && alt && base == 16) \
696 while (width-- > 0) \
700 outstring (string + 1, workend - string); \
706 if (number.word != 0 && alt && base == 16) \
719 width -= workend - string; \
720 outstring (string + 1, workend - string); \
726 LABEL (form_float): \
728 /* Floating-point number. This is handled by printf_fp.c. */ \
729 extern int __printf_fp __P ((FILE *, const struct printf_info *, \
730 const void **const)); \
736 struct printf_info info = { prec: prec, \
739 is_long_double: is_long_double, \
740 is_short: is_short, \
745 showsign: showsign, \
750 if (is_long_double) \
751 the_arg.pa_long_double = va_arg (ap, long double); \
753 the_arg.pa_double = va_arg (ap, double); \
754 ptr = (const void *) &the_arg; \
756 function_done = __printf_fp (s, &info, &ptr); \
760 ptr = (const void *) &args_value[fspec->data_arg]; \
762 function_done = __printf_fp (s, &fspec->info, &ptr); \
765 if (function_done < 0) \
766 /* Error in print handler. */ \
769 done += function_done; \
773 LABEL (form_floathex): \
775 /* FLoating point number printed as hexadecimal number. */ \
776 extern int __printf_fphex __P ((FILE *, const struct printf_info *, \
777 const void **const)); \
783 struct printf_info info = { prec: prec, \
786 is_long_double: is_long_double, \
787 is_short: is_short, \
792 showsign: showsign, \
797 if (is_long_double) \
798 the_arg.pa_long_double = va_arg (ap, long double); \
800 the_arg.pa_double = va_arg (ap, double); \
801 ptr = (const void *) &the_arg; \
803 function_done = __printf_fphex (s, &info, &ptr); \
807 ptr = (const void *) &args_value[fspec->data_arg]; \
809 function_done = __printf_fphex (s, &fspec->info, &ptr); \
812 if (function_done < 0) \
813 /* Error in print handler. */ \
816 done += function_done; \
820 LABEL (form_character): \
823 goto LABEL (form_wcharacter); \
824 --width; /* Account for the character itself. */ \
828 outchar ((unsigned char) va_arg (ap, int)); /* Promoted. */ \
830 outchar ((unsigned char) args_value[fspec->data_arg].pa_char); \
835 LABEL (form_wcharacter): \
837 /* Wide character. */ \
838 char buf[MB_CUR_MAX]; \
842 memset (&mbstate, '\0', sizeof (mbstate_t)); \
843 len = __wcrtomb (buf, (fspec == NULL ? va_arg (ap, wint_t) \
844 : args_value[fspec->data_arg].pa_wchar), \
849 outstring (buf, len); \
855 LABEL (form_string): \
859 /* The string argument could in fact be `char *' or `wchar_t *'. \
860 But this should not make a difference here. */ \
862 string = (char *) va_arg (ap, const char *); \
864 string = (char *) args_value[fspec->data_arg].pa_string; \
866 /* Entry point for printing other strings. */ \
867 LABEL (print_string): \
869 if (string == NULL) \
871 /* Write "(null)" if there's space. */ \
872 if (prec == -1 || prec >= (int) sizeof (null) - 1) \
874 string = (char *) null; \
875 len = sizeof (null) - 1; \
879 string = (char *) ""; \
883 else if (!is_long && spec != L_('S')) \
886 /* Search for the end of the string, but don't search past \
887 the length specified by the precision. */ \
888 len = strnlen (string, prec); \
890 len = strlen (string); \
894 const wchar_t *s2 = (const wchar_t *) string; \
897 memset (&mbstate, '\0', sizeof (mbstate_t)); \
898 len = __wcsrtombs (NULL, &s2, 0, &mbstate); \
899 if (len == (size_t) -1) \
900 /* Illegal wide-character string. */ \
903 assert (__mbsinit (&mbstate)); \
904 s2 = (const wchar_t *) string; \
905 string = alloca (len + 1); \
906 (void) __wcsrtombs (string, &s2, len + 1, &mbstate); \
911 if ((width -= len) < 0) \
913 outstring (string, len); \
919 outstring (string, len); \
925 LABEL (form_pointer): \
926 /* Generic pointer. */ \
930 ptr = va_arg (ap, void *); \
932 ptr = args_value[fspec->data_arg].pa_pointer; \
935 /* If the pointer is not NULL, write it as a %#x spec. */ \
937 number.word = (unsigned long int) ptr; \
942 goto LABEL (number); \
946 /* Write "(nil)" for a nil pointer. */ \
947 string = (char *) "(nil)"; \
948 /* Make sure the full string "(nil)" is printed. */ \
951 is_long = 0; /* This is no wide-char string. */ \
952 goto LABEL (print_string); \
957 LABEL (form_number): \
958 /* Answer the count of characters written. */ \
962 *(long long int *) va_arg (ap, void *) = done; \
964 *(long int *) va_arg (ap, void *) = done; \
965 else if (!is_short) \
966 *(int *) va_arg (ap, void *) = done; \
968 *(short int *) va_arg (ap, void *) = done; \
972 *(long long int *) args_value[fspec->data_arg].pa_pointer = done; \
974 *(long int *) args_value[fspec->data_arg].pa_pointer = done; \
975 else if (!is_short) \
976 *(int *) args_value[fspec->data_arg].pa_pointer = done; \
978 *(short int *) args_value[fspec->data_arg].pa_pointer = done; \
981 LABEL (form_strerror): \
982 /* Print description of error ERRNO. */ \
984 (char *) __strerror_r (save_errno, work_buffer, sizeof work_buffer); \
985 is_long = 0; /* This is no wide-char string. */ \
986 goto LABEL (print_string)
989 /* Sanity check of arguments. */
990 ARGCHECK (s
, format
);
992 if (UNBUFFERED_P (s
))
993 /* Use a helper function which will allocate a local temporary buffer
994 for the stream and then call us again. */
995 return buffered_vfprintf (s
, format
, ap
);
997 /* Initialize local variables. */
999 grouping
= (const char *) -1;
1001 /* This macro will be available soon in gcc's <stdarg.h>. We need it
1002 since on some systems `va_list' is not an integral type. */
1003 __va_copy (ap_save
, ap
);
1009 /* Put state for processing format string in initial state. */
1010 memset (&mbstate
, '\0', sizeof (mbstate_t));
1012 /* Find the first format specifier. */
1013 f
= lead_str_end
= find_spec (format
, &mbstate
);
1017 __libc_cleanup_region_start ((void (*) (void *)) &_IO_funlockfile
, s
);
1020 __libc_cleanup_region_start ((void (*) (void *)) &__funlockfile
, s
);
1024 /* Write the literal text before the first format. */
1025 outstring ((const UCHAR_T
*) format
,
1026 lead_str_end
- (const UCHAR_T
*) format
);
1028 /* If we only have to print a simple string, return now. */
1032 /* Process whole format string. */
1035 #define REF(Name) &&do_##Name
1036 #define LABEL(Name) do_##Name
1040 union printf_arg
*args_value
; /* This is not used here but ... */
1041 int is_negative
; /* Flag for negative number. */
1044 unsigned long long int longlong
;
1045 unsigned long int word
;
1048 union printf_arg the_arg
;
1049 char *string
; /* Pointer to argument string. */
1050 int alt
= 0; /* Alternate format. */
1051 int space
= 0; /* Use space prefix if no sign is needed. */
1052 int left
= 0; /* Left-justify output. */
1053 int showsign
= 0; /* Always begin with plus or minus sign. */
1054 int group
= 0; /* Print numbers according grouping rules. */
1055 int is_long_double
= 0; /* Argument is long double/ long long int. */
1056 int is_short
= 0; /* Argument is long int. */
1057 int is_long
= 0; /* Argument is short int. */
1058 int is_char
= 0; /* Argument is promoted (unsigned) char. */
1059 int width
= 0; /* Width of output; 0 means none specified. */
1060 int prec
= -1; /* Precision of output; -1 means none specified. */
1061 char pad
= ' '; /* Padding character. */
1064 /* Get current character in format string. */
1065 JUMP (*++f
, step0_jumps
);
1070 JUMP (*++f
, step0_jumps
);
1075 JUMP (*++f
, step0_jumps
);
1081 JUMP (*++f
, step0_jumps
);
1086 JUMP (*++f
, step0_jumps
);
1092 JUMP (*++f
, step0_jumps
);
1094 /* The '\'' flag. */
1098 /* XXX Completely wrong. Use wctob. */
1099 if (grouping
== (const char *) -1)
1101 /* Figure out the thousands separator character. */
1102 if (mbtowc (&thousands_sep
,
1103 _NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
),
1104 strlen (_NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
))) <= 0)
1105 thousands_sep
= (wchar_t)
1106 *_NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
);
1107 grouping
= _NL_CURRENT (LC_NUMERIC
, GROUPING
);
1108 if (*grouping
== '\0' || *grouping
== CHAR_MAX
1109 || thousands_sep
== L
'\0')
1112 JUMP (*++f
, step0_jumps
);
1114 /* Get width from argument. */
1115 LABEL (width_asterics
):
1117 const UCHAR_T
*tmp
; /* Temporary value. */
1120 if (ISDIGIT (*tmp
) && read_int (&tmp
) && *tmp
== L_('$'))
1121 /* The width comes from a positional parameter. */
1124 width
= va_arg (ap
, int);
1126 /* Negative width means left justified. */
1134 JUMP (*f
, step1_jumps
);
1136 /* Given width in format string. */
1138 width
= read_int (&f
);
1140 /* Oh, oh. The argument comes from a positional parameter. */
1142 JUMP (*f
, step1_jumps
);
1148 const UCHAR_T
*tmp
; /* Temporary value. */
1151 if (ISDIGIT (*tmp
) && read_int (&tmp
) > 0 && *tmp
== L_('$'))
1152 /* The precision comes from a positional parameter. */
1155 prec
= va_arg (ap
, int);
1157 /* If the precision is negative the precision is omitted. */
1161 else if (ISDIGIT (*f
))
1162 prec
= read_int (&f
);
1165 JUMP (*f
, step2_jumps
);
1167 /* Process 'h' modifier. There might another 'h' following. */
1170 JUMP (*++f
, step3a_jumps
);
1172 /* Process 'hh' modifier. */
1173 LABEL (mod_halfhalf
):
1176 JUMP (*++f
, step4_jumps
);
1178 /* Process 'l' modifier. There might another 'l' following. */
1181 JUMP (*++f
, step3b_jumps
);
1183 /* Process 'L', 'q', or 'll' modifier. No other modifier is
1184 allowed to follow. */
1185 LABEL (mod_longlong
):
1187 JUMP (*++f
, step4_jumps
);
1190 is_longlong
= sizeof (size_t) > sizeof (unsigned long int);
1191 is_long
= sizeof (size_t) > sizeof (unsigned int);
1192 JUMP (*++f
, step4_jumps
);
1194 LABEL (mod_ptrdiff_t
):
1195 is_longlong
= sizeof (ptrdiff_t) > sizeof (unsigned long int);
1196 is_long
= sizeof (ptrdiff_t) > sizeof (unsigned int);
1197 JUMP (*++f
, step4_jumps
);
1199 LABEL (mod_intmax_t
):
1200 is_longlong
= sizeof (intmax_t) > sizeof (unsigned long int);
1201 is_long
= sizeof (intmax_t) > sizeof (unsigned int);
1202 JUMP (*++f
, step4_jumps
);
1204 /* Process current format. */
1207 process_arg (((struct printf_spec
*) NULL
));
1209 LABEL (form_unknown
):
1210 if (spec
== L_('\0'))
1212 /* The format string ended before the specifier is complete. */
1217 /* If we are in the fast loop force entering the complicated
1222 /* The format is correctly handled. */
1225 /* Look for next format specifier. */
1226 f
= find_spec ((end_of_spec
= ++f
), &mbstate
);
1228 /* Write the following constant string. */
1229 outstring (end_of_spec
, f
- end_of_spec
);
1231 while (*f
!= L_('\0'));
1233 /* Unlock stream and return. */
1236 /* Here starts the more complex loop to handle positional parameters. */
1239 /* Array with information about the needed arguments. This has to
1240 be dynamically extensible. */
1242 size_t nspecs_max
= 32; /* A more or less arbitrary start value. */
1243 struct printf_spec
*specs
1244 = alloca (nspecs_max
* sizeof (struct printf_spec
));
1246 /* The number of arguments the format string requests. This will
1247 determine the size of the array needed to store the argument
1251 union printf_arg
*args_value
;
1253 /* Positional parameters refer to arguments directly. This could
1254 also determine the maximum number of arguments. Track the
1256 size_t max_ref_arg
= 0;
1258 /* Just a counter. */
1262 if (grouping
== (const char *) -1)
1264 /* XXX Use wctob. But this is incompatible for now. */
1265 /* Figure out the thousands separator character. */
1266 if (mbtowc (&thousands_sep
,
1267 _NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
),
1268 strlen (_NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
))) <= 0)
1269 thousands_sep
= (wchar_t) *_NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
);
1270 grouping
= _NL_CURRENT (LC_NUMERIC
, GROUPING
);
1271 if (*grouping
== '\0' || *grouping
== CHAR_MAX
1272 || thousands_sep
== L
'\0')
1276 for (f
= lead_str_end
; *f
!= '\0'; f
= specs
[nspecs
++].next_fmt
)
1278 if (nspecs
>= nspecs_max
)
1280 /* Extend the array of format specifiers. */
1281 struct printf_spec
*old
= specs
;
1284 specs
= alloca (nspecs_max
* sizeof (struct printf_spec
));
1286 if (specs
== &old
[nspecs
])
1287 /* Stack grows up, OLD was the last thing allocated;
1289 nspecs_max
+= nspecs_max
/ 2;
1292 /* Copy the old array's elements to the new space. */
1293 memcpy (specs
, old
, nspecs
* sizeof (struct printf_spec
));
1294 if (old
== &specs
[nspecs
])
1295 /* Stack grows down, OLD was just below the new
1296 SPECS. We can use that space when the new space
1298 nspecs_max
+= nspecs_max
/ 2;
1302 /* Parse the format specifier. */
1303 nargs
+= parse_one_spec (f
, nargs
, &specs
[nspecs
], &max_ref_arg
,
1307 /* Determine the number of arguments the format string consumes. */
1308 nargs
= MAX (nargs
, max_ref_arg
);
1310 /* Allocate memory for the argument descriptions. */
1311 args_type
= alloca (nargs
* sizeof (int));
1312 memset (args_type
, 0, nargs
* sizeof (int));
1313 args_value
= alloca (nargs
* sizeof (union printf_arg
));
1315 /* XXX Could do sanity check here: If any element in ARGS_TYPE is
1316 still zero after this loop, format is invalid. For now we
1317 simply use 0 as the value. */
1319 /* Fill in the types of all the arguments. */
1320 for (cnt
= 0; cnt
< nspecs
; ++cnt
)
1322 /* If the width is determined by an argument this is an int. */
1323 if (specs
[cnt
].width_arg
!= -1)
1324 args_type
[specs
[cnt
].width_arg
] = PA_INT
;
1326 /* If the precision is determined by an argument this is an int. */
1327 if (specs
[cnt
].prec_arg
!= -1)
1328 args_type
[specs
[cnt
].prec_arg
] = PA_INT
;
1330 switch (specs
[cnt
].ndata_args
)
1332 case 0: /* No arguments. */
1334 case 1: /* One argument; we already have the type. */
1335 args_type
[specs
[cnt
].data_arg
] = specs
[cnt
].data_arg_type
;
1338 /* We have more than one argument for this format spec.
1339 We must call the arginfo function again to determine
1341 (void) (*__printf_arginfo_table
[specs
[cnt
].info
.spec
])
1343 specs
[cnt
].ndata_args
, &args_type
[specs
[cnt
].data_arg
]);
1348 /* Now we know all the types and the order. Fill in the argument
1350 for (cnt
= 0; cnt
< nargs
; ++cnt
)
1351 switch (args_type
[cnt
])
1353 #define T(tag, mem, type) \
1355 args_value[cnt].mem = va_arg (ap_save, type); \
1358 T (PA_CHAR
, pa_char
, int); /* Promoted. */
1359 T (PA_WCHAR
, pa_wchar
, wint_t);
1360 T (PA_INT
|PA_FLAG_SHORT
, pa_short_int
, int); /* Promoted. */
1361 T (PA_INT
, pa_int
, int);
1362 T (PA_INT
|PA_FLAG_LONG
, pa_long_int
, long int);
1363 T (PA_INT
|PA_FLAG_LONG_LONG
, pa_long_long_int
, long long int);
1364 T (PA_FLOAT
, pa_float
, double); /* Promoted. */
1365 T (PA_DOUBLE
, pa_double
, double);
1366 T (PA_DOUBLE
|PA_FLAG_LONG_DOUBLE
, pa_long_double
, long double);
1367 T (PA_STRING
, pa_string
, const char *);
1368 T (PA_WSTRING
, pa_wstring
, const wchar_t *);
1369 T (PA_POINTER
, pa_pointer
, void *);
1372 if ((args_type
[cnt
] & PA_FLAG_PTR
) != 0)
1373 args_value
[cnt
].pa_pointer
= va_arg (ap_save
, void *);
1375 args_value
[cnt
].pa_long_double
= 0.0;
1379 /* Now walk through all format specifiers and process them. */
1380 for (; (size_t) nspecs_done
< nspecs
; ++nspecs_done
)
1383 #define REF(Name) &&do2_##Name
1385 #define LABEL(Name) do2_##Name
1391 unsigned long long int longlong
;
1392 unsigned long int word
;
1395 union printf_arg the_arg
;
1396 char *string
; /* Pointer to argument string. */
1398 /* Fill variables from values in struct. */
1399 int alt
= specs
[nspecs_done
].info
.alt
;
1400 int space
= specs
[nspecs_done
].info
.space
;
1401 int left
= specs
[nspecs_done
].info
.left
;
1402 int showsign
= specs
[nspecs_done
].info
.showsign
;
1403 int group
= specs
[nspecs_done
].info
.group
;
1404 int is_long_double
= specs
[nspecs_done
].info
.is_long_double
;
1405 int is_short
= specs
[nspecs_done
].info
.is_short
;
1406 int is_char
= specs
[nspecs_done
].info
.is_char
;
1407 int is_long
= specs
[nspecs_done
].info
.is_long
;
1408 int width
= specs
[nspecs_done
].info
.width
;
1409 int prec
= specs
[nspecs_done
].info
.prec
;
1410 char pad
= specs
[nspecs_done
].info
.pad
;
1411 CHAR_T spec
= specs
[nspecs_done
].info
.spec
;
1413 /* Fill in last information. */
1414 if (specs
[nspecs_done
].width_arg
!= -1)
1416 /* Extract the field width from an argument. */
1417 specs
[nspecs_done
].info
.width
=
1418 args_value
[specs
[nspecs_done
].width_arg
].pa_int
;
1420 if (specs
[nspecs_done
].info
.width
< 0)
1421 /* If the width value is negative left justification is
1422 selected and the value is taken as being positive. */
1424 specs
[nspecs_done
].info
.width
*= -1;
1425 left
= specs
[nspecs_done
].info
.left
= 1;
1427 width
= specs
[nspecs_done
].info
.width
;
1430 if (specs
[nspecs_done
].prec_arg
!= -1)
1432 /* Extract the precision from an argument. */
1433 specs
[nspecs_done
].info
.prec
=
1434 args_value
[specs
[nspecs_done
].prec_arg
].pa_int
;
1436 if (specs
[nspecs_done
].info
.prec
< 0)
1437 /* If the precision is negative the precision is
1439 specs
[nspecs_done
].info
.prec
= -1;
1441 prec
= specs
[nspecs_done
].info
.prec
;
1444 /* Process format specifiers. */
1447 JUMP (spec
, step4_jumps
);
1449 process_arg ((&specs
[nspecs_done
]));
1451 LABEL (form_unknown
):
1453 extern printf_function
**__printf_function_table
;
1455 printf_function
*function
;
1460 (__printf_function_table
== NULL
? NULL
:
1461 __printf_function_table
[specs
[nspecs_done
].info
.spec
]);
1463 if (function
== NULL
)
1464 function
= &printf_unknown
;
1466 ptr
= alloca (specs
[nspecs_done
].ndata_args
1467 * sizeof (const void *));
1469 /* Fill in an array of pointers to the argument values. */
1470 for (i
= 0; i
< specs
[nspecs_done
].ndata_args
; ++i
)
1471 ptr
[i
] = &args_value
[specs
[nspecs_done
].data_arg
+ i
];
1473 /* Call the function. */
1474 function_done
= (*function
) (s
, &specs
[nspecs_done
].info
, ptr
);
1476 /* If an error occurred we don't have information about #
1478 if (function_done
< 0)
1484 done
+= function_done
;
1489 /* Write the following constant string. */
1490 outstring (specs
[nspecs_done
].end_of_fmt
,
1491 specs
[nspecs_done
].next_fmt
1492 - specs
[nspecs_done
].end_of_fmt
);
1497 /* Unlock the stream. */
1499 _IO_funlockfile (s
);
1503 __libc_cleanup_region_end (0);
1510 # ifdef strong_alias
1511 /* This is for glibc. */
1512 strong_alias (_IO_vfprintf
, vfprintf
);
1514 # if defined __ELF__ || defined __GNU_LIBRARY__
1515 # include <gnu-stabs.h>
1517 weak_alias (_IO_vfprintf
, vfprintf
);
1523 /* Handle an unknown format specifier. This prints out a canonicalized
1524 representation of the format spec itself. */
1526 printf_unknown (FILE *s
, const struct printf_info
*info
,
1527 const void *const *args
)
1531 char work_buffer
[BUFSIZ
];
1542 else if (info
->space
)
1546 if (info
->pad
== '0')
1549 if (info
->width
!= 0)
1551 w
= _itoa_word (info
->width
, workend
+ 1, 10, 0);
1552 while (w
<= workend
)
1556 if (info
->prec
!= -1)
1559 w
= _itoa_word (info
->prec
, workend
+ 1, 10, 0);
1560 while (w
<= workend
)
1564 if (info
->spec
!= '\0')
1565 outchar (info
->spec
);
1570 /* Group the digits according to the grouping rules of the current locale.
1571 The interpretation of GROUPING is as in `struct lconv' from <locale.h>. */
1574 group_number (CHAR_T
*w
, CHAR_T
*rear_ptr
, const CHAR_T
*grouping
,
1575 wchar_t thousands_sep
)
1580 /* We treat all negative values like CHAR_MAX. */
1582 if (*grouping
== CHAR_MAX
|| *grouping
<= 0)
1583 /* No grouping should be done. */
1588 /* Copy existing string so that nothing gets overwritten. */
1589 src
= (char *) alloca (rear_ptr
- w
);
1590 s
= (char *) __mempcpy (src
, w
+ 1, rear_ptr
- w
) - 1;
1593 /* Process all characters in the string. */
1598 if (--len
== 0 && s
>= src
)
1600 /* A new group begins. */
1601 *w
-- = thousands_sep
;
1604 if (*grouping
== '\0')
1605 /* The previous grouping repeats ad infinitum. */
1607 else if (*grouping
== CHAR_MAX
1613 /* No further grouping to be done.
1614 Copy the rest of the number. */
1626 /* Helper "class" for `fprintf to unbuffered': creates a temporary buffer. */
1629 struct _IO_FILE_plus _f
;
1630 _IO_FILE
*_put_stream
;
1631 #ifdef _IO_MTSAFE_IO
1637 _IO_helper_overflow (_IO_FILE
*s
, int c
)
1639 _IO_FILE
*target
= ((struct helper_file
*) s
)->_put_stream
;
1640 int used
= s
->_IO_write_ptr
- s
->_IO_write_base
;
1643 _IO_size_t written
= _IO_sputn (target
, s
->_IO_write_base
, used
);
1644 s
->_IO_write_ptr
-= written
;
1649 static const struct _IO_jump_t _IO_helper_jumps
=
1652 JUMP_INIT (finish
, _IO_default_finish
),
1653 JUMP_INIT (overflow
, _IO_helper_overflow
),
1654 JUMP_INIT (underflow
, _IO_default_underflow
),
1655 JUMP_INIT (uflow
, _IO_default_uflow
),
1656 JUMP_INIT (pbackfail
, _IO_default_pbackfail
),
1657 JUMP_INIT (xsputn
, _IO_default_xsputn
),
1658 JUMP_INIT (xsgetn
, _IO_default_xsgetn
),
1659 JUMP_INIT (seekoff
, _IO_default_seekoff
),
1660 JUMP_INIT (seekpos
, _IO_default_seekpos
),
1661 JUMP_INIT (setbuf
, _IO_default_setbuf
),
1662 JUMP_INIT (sync
, _IO_default_sync
),
1663 JUMP_INIT (doallocate
, _IO_default_doallocate
),
1664 JUMP_INIT (read
, _IO_default_read
),
1665 JUMP_INIT (write
, _IO_default_write
),
1666 JUMP_INIT (seek
, _IO_default_seek
),
1667 JUMP_INIT (close
, _IO_default_close
),
1668 JUMP_INIT (stat
, _IO_default_stat
)
1673 buffered_vfprintf (register _IO_FILE
*s
, const CHAR_T
*format
,
1676 char buf
[_IO_BUFSIZ
];
1677 struct helper_file helper
;
1678 register _IO_FILE
*hp
= (_IO_FILE
*) &helper
;
1679 int result
, to_flush
;
1681 /* Initialize helper. */
1682 helper
._put_stream
= s
;
1683 hp
->_IO_write_base
= buf
;
1684 hp
->_IO_write_ptr
= buf
;
1685 hp
->_IO_write_end
= buf
+ sizeof buf
;
1686 hp
->_IO_file_flags
= _IO_MAGIC
|_IO_NO_READS
;
1687 #if _IO_JUMPS_OFFSET
1688 hp
->_vtable_offset
= 0;
1690 #ifdef _IO_MTSAFE_IO
1691 hp
->_lock
= &helper
.lock
;
1692 __libc_lock_init (*hp
->_lock
);
1694 _IO_JUMPS (hp
) = (struct _IO_jump_t
*) &_IO_helper_jumps
;
1696 /* Now print to helper instead. */
1697 result
= _IO_vfprintf (hp
, format
, args
);
1699 /* Now flush anything from the helper to the S. */
1700 if ((to_flush
= hp
->_IO_write_ptr
- hp
->_IO_write_base
) > 0)
1702 if ((int) _IO_sputn (s
, hp
->_IO_write_base
, to_flush
) != to_flush
)
1709 #else /* !USE_IN_LIBIO */
1713 buffered_vfprintf (register FILE *s
, const CHAR_T
*format
, va_list args
)
1718 s
->__bufp
= s
->__buffer
= buf
;
1719 s
->__bufsize
= sizeof buf
;
1720 s
->__put_limit
= s
->__buffer
+ s
->__bufsize
;
1721 s
->__get_limit
= s
->__buffer
;
1723 /* Now use buffer to print. */
1724 result
= vfprintf (s
, format
, args
);
1726 if (fflush (s
) == EOF
)
1728 s
->__buffer
= s
->__bufp
= s
->__get_limit
= s
->__put_limit
= NULL
;
1734 /* Pads string with given number of a specified character.
1735 This code is taken from iopadn.c of the GNU I/O library. */
1737 static const CHAR_T blanks
[PADSIZE
] =
1738 { L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' '),
1739 L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' ') };
1740 static const CHAR_T zeroes
[PADSIZE
] =
1741 { L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0'),
1742 L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0') };
1745 #ifndef COMPILE_WPRINTF
1746 __printf_pad (FILE *s
, char pad
, size_t count
)
1748 __wprintf_pad (FILE *s
, wchar_t pad
, size_t count
)
1751 const CHAR_T
*padptr
;
1754 padptr
= pad
== L_(' ') ? blanks
: zeroes
;
1756 for (i
= count
; i
>= PADSIZE
; i
-= PADSIZE
)
1757 if (PUT (s
, padptr
, PADSIZE
) != PADSIZE
)
1760 if (PUT (s
, padptr
, i
) != i
)
1766 #endif /* USE_IN_LIBIO */