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); \
65 # define vfprintf vfwprintf
66 # define CHAR_T wchar_t
67 # define UCHAR_T uwchar_t
69 # define L_(Str) L##Str
70 # define ISDIGIT(Ch) iswdigit (Ch)
73 # define PUT(F, S, N) _IO_sputn ((F), (S), (N))
74 # define PAD(Padchar) \
76 done += _IO_wpadn (s, (Padchar), width)
78 # define PUTC(C, F) wputc (C, F)
79 ssize_t __wprintf_pad
__P ((FILE *, wchar_t pad
, size_t n
));
80 # define PAD(Padchar) \
82 { ssize_t __res = __wprintf_pad (s, (Padchar), width); \
92 /* Include the shared code for parsing the format string. */
93 #include "printf-parse.h"
97 /* This code is for use in libio. */
99 # define PUTC(C, F) _IO_putc_unlocked (C, F)
100 # define vfprintf _IO_vfprintf
101 # define FILE _IO_FILE
103 # define va_list _IO_va_list
105 # define BUFSIZ _IO_BUFSIZ
106 # define ARGCHECK(S, Format) \
109 /* Check file argument for consistence. */ \
110 CHECK_FILE (S, -1); \
111 if (S->_flags & _IO_NO_WRITES) \
113 __set_errno (EBADF); \
116 if (Format == NULL) \
122 # define UNBUFFERED_P(S) ((S)->_IO_file_flags & _IO_UNBUFFERED)
123 #else /* ! USE_IN_LIBIO */
124 /* This code is for use in the GNU C library. */
126 # define PUT(F, S, N) fwrite (S, 1, N, F)
127 # define ARGCHECK(S, Format) \
130 /* Check file argument for consistence. */ \
131 if (!__validfp (S) || !S->__mode.__write) \
133 __set_errno (EBADF); \
136 if (Format == NULL) \
138 __set_errno (EINVAL); \
143 if (__flshfp (S, EOF) == EOF) \
148 # define UNBUFFERED_P(s) ((s)->__buffer == NULL)
150 /* XXX These declarations should go as soon as the stdio header files
151 have these prototypes. */
152 extern void __flockfile (FILE *);
153 extern void __funlockfile (FILE *);
154 #endif /* USE_IN_LIBIO */
157 #define outchar(Ch) \
160 register const int outc = (Ch); \
161 if (PUTC (outc, s) == EOF) \
171 #define outstring(String, Len) \
174 if ((size_t) PUT (s, (String), (Len)) != (size_t) (Len)) \
183 /* For handling long_double and longlong we use the same flag. */
185 # define is_longlong is_long_double
189 /* Global variables. */
190 static const char null
[] = "(null)";
193 /* Helper function to provide temporary buffering for unbuffered streams. */
194 static int buffered_vfprintf
__P ((FILE *stream
, const CHAR_T
*fmt
, va_list))
197 /* Handle unknown format specifier. */
198 static int printf_unknown
__P ((FILE *, const struct printf_info
*,
199 const void *const *));
201 /* Group digits of number string. */
202 static char *group_number
__P ((CHAR_T
*, CHAR_T
*, const CHAR_T
*, wchar_t))
206 /* The function itself. */
208 vfprintf (FILE *s
, const CHAR_T
*format
, va_list ap
)
210 /* The character used as thousands separator. */
211 wchar_t thousands_sep
;
213 /* The string describing the size of groups of digits. */
214 const char *grouping
;
216 /* Place to accumulate the result. */
219 /* Current character in format string. */
222 /* End of leading constant string. */
223 const UCHAR_T
*lead_str_end
;
225 /* Points to next format specifier. */
226 const UCHAR_T
*end_of_spec
;
228 /* Buffer intermediate results. */
229 char work_buffer
[1000];
230 #define workend (&work_buffer[sizeof (work_buffer) - 1])
232 /* State for restartable multibyte character handling functions. */
235 /* We have to save the original argument pointer. */
238 /* Count number of specifiers we already processed. */
241 /* For the %m format we may need the current `errno' value. */
242 int save_errno
= errno
;
245 /* This table maps a character into a number representing a
246 class. In each step there is a destination label for each
248 static const int jump_table
[] =
250 /* ' ' */ 1, 0, 0, /* '#' */ 4,
251 0, /* '%' */ 14, 0, /* '\''*/ 6,
252 0, 0, /* '*' */ 7, /* '+' */ 2,
253 0, /* '-' */ 3, /* '.' */ 9, 0,
254 /* '0' */ 5, /* '1' */ 8, /* '2' */ 8, /* '3' */ 8,
255 /* '4' */ 8, /* '5' */ 8, /* '6' */ 8, /* '7' */ 8,
256 /* '8' */ 8, /* '9' */ 8, 0, 0,
258 0, /* 'A' */ 26, 0, /* 'C' */ 25,
259 0, /* 'E' */ 19, 0, /* 'G' */ 19,
261 /* 'L' */ 12, 0, 0, 0,
262 0, 0, 0, /* 'S' */ 21,
264 /* 'X' */ 18, 0, /* 'Z' */ 13, 0,
266 0, /* 'a' */ 26, 0, /* 'c' */ 20,
267 /* 'd' */ 15, /* 'e' */ 19, /* 'f' */ 19, /* 'g' */ 19,
268 /* 'h' */ 10, /* 'i' */ 15, /* 'j' */ 28, 0,
269 /* 'l' */ 11, /* 'm' */ 24, /* 'n' */ 23, /* 'o' */ 17,
270 /* 'p' */ 22, /* 'q' */ 12, 0, /* 's' */ 21,
271 /* 't' */ 27, /* 'u' */ 16, 0, 0,
272 /* 'x' */ 18, 0, /* 'z' */ 13
275 #define NOT_IN_JUMP_RANGE(Ch) ((Ch) < ' ' || (Ch) > 'z')
276 #define CHAR_CLASS(Ch) (jump_table[(int) (Ch) - ' '])
277 #define JUMP(ChExpr, table) \
282 ptr = NOT_IN_JUMP_RANGE (spec) ? REF (form_unknown) \
283 : table[CHAR_CLASS (spec)]; \
288 #define STEP0_3_TABLE \
289 /* Step 0: at the beginning. */ \
290 static const void *step0_jumps[29] = \
292 REF (form_unknown), \
293 REF (flag_space), /* for ' ' */ \
294 REF (flag_plus), /* for '+' */ \
295 REF (flag_minus), /* for '-' */ \
296 REF (flag_hash), /* for '<hash>' */ \
297 REF (flag_zero), /* for '0' */ \
298 REF (flag_quote), /* for '\'' */ \
299 REF (width_asterics), /* for '*' */ \
300 REF (width), /* for '1'...'9' */ \
301 REF (precision), /* for '.' */ \
302 REF (mod_half), /* for 'h' */ \
303 REF (mod_long), /* for 'l' */ \
304 REF (mod_longlong), /* for 'L', 'q' */ \
305 REF (mod_size_t), /* for 'z', 'Z' */ \
306 REF (form_percent), /* for '%' */ \
307 REF (form_integer), /* for 'd', 'i' */ \
308 REF (form_unsigned), /* for 'u' */ \
309 REF (form_octal), /* for 'o' */ \
310 REF (form_hexa), /* for 'X', 'x' */ \
311 REF (form_float), /* for 'E', 'e', 'f', 'G', 'g' */ \
312 REF (form_character), /* for 'c' */ \
313 REF (form_string), /* for 's', 'S' */ \
314 REF (form_pointer), /* for 'p' */ \
315 REF (form_number), /* for 'n' */ \
316 REF (form_strerror), /* for 'm' */ \
317 REF (form_wcharacter), /* for 'C' */ \
318 REF (form_floathex), /* for 'A', 'a' */ \
319 REF (mod_ptrdiff_t), /* for 't' */ \
320 REF (mod_intmax_t), /* for 'j' */ \
322 /* Step 1: after processing width. */ \
323 static const void *step1_jumps[29] = \
325 REF (form_unknown), \
326 REF (form_unknown), /* for ' ' */ \
327 REF (form_unknown), /* for '+' */ \
328 REF (form_unknown), /* for '-' */ \
329 REF (form_unknown), /* for '<hash>' */ \
330 REF (form_unknown), /* for '0' */ \
331 REF (form_unknown), /* for '\'' */ \
332 REF (form_unknown), /* for '*' */ \
333 REF (form_unknown), /* for '1'...'9' */ \
334 REF (precision), /* for '.' */ \
335 REF (mod_half), /* for 'h' */ \
336 REF (mod_long), /* for 'l' */ \
337 REF (mod_longlong), /* for 'L', 'q' */ \
338 REF (mod_size_t), /* for 'z', 'Z' */ \
339 REF (form_percent), /* for '%' */ \
340 REF (form_integer), /* for 'd', 'i' */ \
341 REF (form_unsigned), /* for 'u' */ \
342 REF (form_octal), /* for 'o' */ \
343 REF (form_hexa), /* for 'X', 'x' */ \
344 REF (form_float), /* for 'E', 'e', 'f', 'G', 'g' */ \
345 REF (form_character), /* for 'c' */ \
346 REF (form_string), /* for 's', 'S' */ \
347 REF (form_pointer), /* for 'p' */ \
348 REF (form_number), /* for 'n' */ \
349 REF (form_strerror), /* for 'm' */ \
350 REF (form_wcharacter), /* for 'C' */ \
351 REF (form_floathex), /* for 'A', 'a' */ \
352 REF (mod_ptrdiff_t), /* for 't' */ \
353 REF (mod_intmax_t) /* for 'j' */ \
355 /* Step 2: after processing precision. */ \
356 static const void *step2_jumps[29] = \
358 REF (form_unknown), \
359 REF (form_unknown), /* for ' ' */ \
360 REF (form_unknown), /* for '+' */ \
361 REF (form_unknown), /* for '-' */ \
362 REF (form_unknown), /* for '<hash>' */ \
363 REF (form_unknown), /* for '0' */ \
364 REF (form_unknown), /* for '\'' */ \
365 REF (form_unknown), /* for '*' */ \
366 REF (form_unknown), /* for '1'...'9' */ \
367 REF (form_unknown), /* for '.' */ \
368 REF (mod_half), /* for 'h' */ \
369 REF (mod_long), /* for 'l' */ \
370 REF (mod_longlong), /* for 'L', 'q' */ \
371 REF (mod_size_t), /* for 'z', 'Z' */ \
372 REF (form_percent), /* for '%' */ \
373 REF (form_integer), /* for 'd', 'i' */ \
374 REF (form_unsigned), /* for 'u' */ \
375 REF (form_octal), /* for 'o' */ \
376 REF (form_hexa), /* for 'X', 'x' */ \
377 REF (form_float), /* for 'E', 'e', 'f', 'G', 'g' */ \
378 REF (form_character), /* for 'c' */ \
379 REF (form_string), /* for 's', 'S' */ \
380 REF (form_pointer), /* for 'p' */ \
381 REF (form_number), /* for 'n' */ \
382 REF (form_strerror), /* for 'm' */ \
383 REF (form_wcharacter), /* for 'C' */ \
384 REF (form_floathex), /* for 'A', 'a' */ \
385 REF (mod_ptrdiff_t), /* for 't' */ \
386 REF (mod_intmax_t) /* for 'j' */ \
388 /* Step 3a: after processing first 'h' modifier. */ \
389 static const void *step3a_jumps[29] = \
391 REF (form_unknown), \
392 REF (form_unknown), /* for ' ' */ \
393 REF (form_unknown), /* for '+' */ \
394 REF (form_unknown), /* for '-' */ \
395 REF (form_unknown), /* for '<hash>' */ \
396 REF (form_unknown), /* for '0' */ \
397 REF (form_unknown), /* for '\'' */ \
398 REF (form_unknown), /* for '*' */ \
399 REF (form_unknown), /* for '1'...'9' */ \
400 REF (form_unknown), /* for '.' */ \
401 REF (mod_halfhalf), /* for 'h' */ \
402 REF (form_unknown), /* for 'l' */ \
403 REF (form_unknown), /* for 'L', 'q' */ \
404 REF (form_unknown), /* for 'z', 'Z' */ \
405 REF (form_percent), /* for '%' */ \
406 REF (form_integer), /* for 'd', 'i' */ \
407 REF (form_unsigned), /* for 'u' */ \
408 REF (form_octal), /* for 'o' */ \
409 REF (form_hexa), /* for 'X', 'x' */ \
410 REF (form_unknown), /* for 'E', 'e', 'f', 'G', 'g' */ \
411 REF (form_unknown), /* for 'c' */ \
412 REF (form_unknown), /* for 's', 'S' */ \
413 REF (form_unknown), /* for 'p' */ \
414 REF (form_number), /* for 'n' */ \
415 REF (form_unknown), /* for 'm' */ \
416 REF (form_unknown), /* for 'C' */ \
417 REF (form_unknown), /* for 'A', 'a' */ \
418 REF (form_unknown), /* for 't' */ \
419 REF (form_unknown) /* for 'j' */ \
421 /* Step 3b: after processing first 'l' modifier. */ \
422 static const void *step3b_jumps[29] = \
424 REF (form_unknown), \
425 REF (form_unknown), /* for ' ' */ \
426 REF (form_unknown), /* for '+' */ \
427 REF (form_unknown), /* for '-' */ \
428 REF (form_unknown), /* for '<hash>' */ \
429 REF (form_unknown), /* for '0' */ \
430 REF (form_unknown), /* for '\'' */ \
431 REF (form_unknown), /* for '*' */ \
432 REF (form_unknown), /* for '1'...'9' */ \
433 REF (form_unknown), /* for '.' */ \
434 REF (form_unknown), /* for 'h' */ \
435 REF (mod_longlong), /* for 'l' */ \
436 REF (form_unknown), /* for 'L', 'q' */ \
437 REF (form_unknown), /* for 'z', 'Z' */ \
438 REF (form_percent), /* for '%' */ \
439 REF (form_integer), /* for 'd', 'i' */ \
440 REF (form_unsigned), /* for 'u' */ \
441 REF (form_octal), /* for 'o' */ \
442 REF (form_hexa), /* for 'X', 'x' */ \
443 REF (form_float), /* for 'E', 'e', 'f', 'G', 'g' */ \
444 REF (form_character), /* for 'c' */ \
445 REF (form_string), /* for 's', 'S' */ \
446 REF (form_pointer), /* for 'p' */ \
447 REF (form_number), /* for 'n' */ \
448 REF (form_strerror), /* for 'm' */ \
449 REF (form_wcharacter), /* for 'C' */ \
450 REF (form_floathex), /* for 'A', 'a' */ \
451 REF (form_unknown), /* for 't' */ \
452 REF (form_unknown) /* for 'j' */ \
455 #define STEP4_TABLE \
456 /* Step 4: processing format specifier. */ \
457 static const void *step4_jumps[29] = \
459 REF (form_unknown), \
460 REF (form_unknown), /* for ' ' */ \
461 REF (form_unknown), /* for '+' */ \
462 REF (form_unknown), /* for '-' */ \
463 REF (form_unknown), /* for '<hash>' */ \
464 REF (form_unknown), /* for '0' */ \
465 REF (form_unknown), /* for '\'' */ \
466 REF (form_unknown), /* for '*' */ \
467 REF (form_unknown), /* for '1'...'9' */ \
468 REF (form_unknown), /* for '.' */ \
469 REF (form_unknown), /* for 'h' */ \
470 REF (form_unknown), /* for 'l' */ \
471 REF (form_unknown), /* for 'L', 'q' */ \
472 REF (form_unknown), /* for 'z', 'Z' */ \
473 REF (form_percent), /* for '%' */ \
474 REF (form_integer), /* for 'd', 'i' */ \
475 REF (form_unsigned), /* for 'u' */ \
476 REF (form_octal), /* for 'o' */ \
477 REF (form_hexa), /* for 'X', 'x' */ \
478 REF (form_float), /* for 'E', 'e', 'f', 'G', 'g' */ \
479 REF (form_character), /* for 'c' */ \
480 REF (form_string), /* for 's', 'S' */ \
481 REF (form_pointer), /* for 'p' */ \
482 REF (form_number), /* for 'n' */ \
483 REF (form_strerror), /* for 'm' */ \
484 REF (form_wcharacter), /* for 'C' */ \
485 REF (form_floathex), /* for 'A', 'a' */ \
486 REF (form_unknown), /* for 't' */ \
487 REF (form_unknown) /* for 'j' */ \
491 #define process_arg(fspec) \
492 /* Start real work. We know about all flags and modifiers and \
493 now process the wanted format specifier. */ \
494 LABEL (form_percent): \
495 /* Write a literal "%". */ \
499 LABEL (form_integer): \
500 /* Signed decimal integer. */ \
505 long long int signed_number; \
508 signed_number = va_arg (ap, long long int); \
510 signed_number = args_value[fspec->data_arg].pa_long_long_int; \
512 is_negative = signed_number < 0; \
513 number.longlong = is_negative ? (- signed_number) : signed_number; \
515 goto LABEL (longlong_number); \
519 long int signed_number; \
524 signed_number = va_arg (ap, long int); \
525 else /* `char' and `short int' will be promoted to `int'. */ \
526 signed_number = va_arg (ap, int); \
530 signed_number = args_value[fspec->data_arg].pa_long_int; \
532 signed_number = args_value[fspec->data_arg].pa_int; \
534 is_negative = signed_number < 0; \
535 number.word = is_negative ? (- signed_number) : signed_number; \
537 goto LABEL (number); \
541 LABEL (form_unsigned): \
542 /* Unsigned decimal integer. */ \
544 goto LABEL (unsigned_number); \
547 LABEL (form_octal): \
548 /* Unsigned octal integer. */ \
550 goto LABEL (unsigned_number); \
554 /* Unsigned hexadecimal integer. */ \
557 LABEL (unsigned_number): /* Unsigned number of base BASE. */ \
559 /* ISO specifies the `+' and ` ' flags only for signed \
568 number.longlong = va_arg (ap, unsigned long long int); \
570 number.longlong = args_value[fspec->data_arg].pa_u_long_long_int; \
572 LABEL (longlong_number): \
574 /* Supply a default precision if none was given. */ \
577 /* We have to take care for the '0' flag. If a precision \
578 is given it must be ignored. */ \
581 /* If the precision is 0 and the number is 0 nothing has to \
582 be written for the number, except for the 'o' format in \
584 if (prec == 0 && number.longlong == 0) \
587 if (base == 8 && alt) \
592 /* Put the number in WORK. */ \
593 string = _itoa (number.longlong, workend + 1, base, \
596 if (group && grouping) \
597 string = group_number (string, workend, grouping, \
600 /* Simply further test for num != 0. */ \
601 number.word = number.longlong != 0; \
608 number.word = va_arg (ap, unsigned long int); \
609 else if (!is_short) \
610 number.word = va_arg (ap, unsigned int); \
612 number.word = (unsigned short int) va_arg (ap, unsigned int); \
616 number.word = args_value[fspec->data_arg].pa_u_long_int; \
618 number.word = (unsigned char) \
619 args_value[fspec->data_arg].pa_char; \
620 else if (!is_short) \
621 number.word = args_value[fspec->data_arg].pa_u_int; \
623 number.word = (unsigned short int) \
624 args_value[fspec->data_arg].pa_u_short_int; \
628 /* Supply a default precision if none was given. */ \
631 /* We have to take care for the '0' flag. If a precision \
632 is given it must be ignored. */ \
635 /* If the precision is 0 and the number is 0 nothing has to \
636 be written for the number, except for the 'o' format in \
638 if (prec == 0 && number.word == 0) \
641 if (base == 8 && alt) \
646 /* Put the number in WORK. */ \
647 string = _itoa_word (number.word, workend + 1, base, \
650 if (group && grouping) \
651 string = group_number (string, workend, grouping, \
656 prec -= workend - string; \
659 /* Add zeros to the precision. */ \
662 else if (number.word != 0 && alt && base == 8) \
663 /* Add octal marker. */ \
668 width -= workend - string; \
670 if (number.word != 0 && alt && base == 16) \
671 /* Account for 0X hex marker. */ \
674 if (is_negative || showsign || space) \
679 while (width-- > 0) \
682 if (number.word != 0 && alt && base == 16) \
697 if (number.word != 0 && alt && base == 16) \
710 while (width-- > 0) \
714 outstring (string + 1, workend - string); \
720 if (number.word != 0 && alt && base == 16) \
733 width -= workend - string; \
734 outstring (string + 1, workend - string); \
740 LABEL (form_float): \
742 /* Floating-point number. This is handled by printf_fp.c. */ \
743 extern int __printf_fp __P ((FILE *, const struct printf_info *, \
744 const void **const)); \
750 struct printf_info info = { prec: prec, \
753 is_long_double: is_long_double, \
754 is_short: is_short, \
759 showsign: showsign, \
764 if (is_long_double) \
765 the_arg.pa_long_double = va_arg (ap, long double); \
767 the_arg.pa_double = va_arg (ap, double); \
768 ptr = (const void *) &the_arg; \
770 function_done = __printf_fp (s, &info, &ptr); \
774 ptr = (const void *) &args_value[fspec->data_arg]; \
776 function_done = __printf_fp (s, &fspec->info, &ptr); \
779 if (function_done < 0) \
781 /* Error in print handler. */ \
786 done += function_done; \
790 LABEL (form_floathex): \
792 /* FLoating point number printed as hexadecimal number. */ \
793 extern int __printf_fphex __P ((FILE *, const struct printf_info *, \
794 const void **const)); \
800 struct printf_info info = { prec: prec, \
803 is_long_double: is_long_double, \
804 is_short: is_short, \
809 showsign: showsign, \
814 if (is_long_double) \
815 the_arg.pa_long_double = va_arg (ap, long double); \
817 the_arg.pa_double = va_arg (ap, double); \
818 ptr = (const void *) &the_arg; \
820 function_done = __printf_fphex (s, &info, &ptr); \
824 ptr = (const void *) &args_value[fspec->data_arg]; \
826 function_done = __printf_fphex (s, &fspec->info, &ptr); \
829 if (function_done < 0) \
831 /* Error in print handler. */ \
836 done += function_done; \
840 LABEL (form_character): \
843 goto LABEL (form_wcharacter); \
844 --width; /* Account for the character itself. */ \
848 outchar ((unsigned char) va_arg (ap, int)); /* Promoted. */ \
850 outchar ((unsigned char) args_value[fspec->data_arg].pa_char); \
855 LABEL (form_wcharacter): \
857 /* Wide character. */ \
858 char buf[MB_CUR_MAX]; \
862 memset (&mbstate, '\0', sizeof (mbstate_t)); \
863 len = __wcrtomb (buf, (fspec == NULL ? va_arg (ap, wint_t) \
864 : args_value[fspec->data_arg].pa_wchar), \
869 outstring (buf, len); \
875 LABEL (form_string): \
879 /* The string argument could in fact be `char *' or `wchar_t *'. \
880 But this should not make a difference here. */ \
882 string = (char *) va_arg (ap, const char *); \
884 string = (char *) args_value[fspec->data_arg].pa_string; \
886 /* Entry point for printing other strings. */ \
887 LABEL (print_string): \
889 if (string == NULL) \
891 /* Write "(null)" if there's space. */ \
892 if (prec == -1 || prec >= (int) sizeof (null) - 1) \
894 string = (char *) null; \
895 len = sizeof (null) - 1; \
899 string = (char *) ""; \
903 else if (!is_long && spec != L_('S')) \
906 /* Search for the end of the string, but don't search past \
907 the length specified by the precision. */ \
908 len = strnlen (string, prec); \
910 len = strlen (string); \
914 const wchar_t *s2 = (const wchar_t *) string; \
917 memset (&mbstate, '\0', sizeof (mbstate_t)); \
918 len = __wcsrtombs (NULL, &s2, 0, &mbstate); \
919 if (len == (size_t) -1) \
921 /* Illegal wide-character string. */ \
926 assert (__mbsinit (&mbstate)); \
927 s2 = (const wchar_t *) string; \
928 string = alloca (len + 1); \
929 (void) __wcsrtombs (string, &s2, len + 1, &mbstate); \
934 if ((width -= len) < 0) \
936 outstring (string, len); \
942 outstring (string, len); \
948 LABEL (form_pointer): \
949 /* Generic pointer. */ \
953 ptr = va_arg (ap, void *); \
955 ptr = args_value[fspec->data_arg].pa_pointer; \
958 /* If the pointer is not NULL, write it as a %#x spec. */ \
960 number.word = (unsigned long int) ptr; \
965 goto LABEL (number); \
969 /* Write "(nil)" for a nil pointer. */ \
970 string = (char *) "(nil)"; \
971 /* Make sure the full string "(nil)" is printed. */ \
974 is_long = 0; /* This is no wide-char string. */ \
975 goto LABEL (print_string); \
980 LABEL (form_number): \
981 /* Answer the count of characters written. */ \
985 *(long long int *) va_arg (ap, void *) = done; \
987 *(long int *) va_arg (ap, void *) = done; \
988 else if (!is_short) \
989 *(int *) va_arg (ap, void *) = done; \
991 *(short int *) va_arg (ap, void *) = done; \
995 *(long long int *) args_value[fspec->data_arg].pa_pointer = done; \
997 *(long int *) args_value[fspec->data_arg].pa_pointer = done; \
998 else if (!is_short) \
999 *(int *) args_value[fspec->data_arg].pa_pointer = done; \
1001 *(short int *) args_value[fspec->data_arg].pa_pointer = done; \
1004 LABEL (form_strerror): \
1005 /* Print description of error ERRNO. */ \
1007 (char *) __strerror_r (save_errno, work_buffer, sizeof work_buffer); \
1008 is_long = 0; /* This is no wide-char string. */ \
1009 goto LABEL (print_string)
1012 /* Sanity check of arguments. */
1013 ARGCHECK (s
, format
);
1015 if (UNBUFFERED_P (s
))
1016 /* Use a helper function which will allocate a local temporary buffer
1017 for the stream and then call us again. */
1018 return buffered_vfprintf (s
, format
, ap
);
1020 /* Initialize local variables. */
1022 grouping
= (const char *) -1;
1024 /* This macro will be available soon in gcc's <stdarg.h>. We need it
1025 since on some systems `va_list' is not an integral type. */
1026 __va_copy (ap_save
, ap
);
1032 /* Put state for processing format string in initial state. */
1033 memset (&mbstate
, '\0', sizeof (mbstate_t));
1035 /* Find the first format specifier. */
1036 f
= lead_str_end
= find_spec (format
, &mbstate
);
1040 __libc_cleanup_region_start ((void (*) (void *)) &_IO_funlockfile
, s
);
1043 __libc_cleanup_region_start ((void (*) (void *)) &__funlockfile
, s
);
1047 /* Write the literal text before the first format. */
1048 outstring ((const UCHAR_T
*) format
,
1049 lead_str_end
- (const UCHAR_T
*) format
);
1051 /* If we only have to print a simple string, return now. */
1055 /* Process whole format string. */
1058 #define REF(Name) &&do_##Name
1059 #define LABEL(Name) do_##Name
1063 union printf_arg
*args_value
; /* This is not used here but ... */
1064 int is_negative
; /* Flag for negative number. */
1067 unsigned long long int longlong
;
1068 unsigned long int word
;
1071 union printf_arg the_arg
;
1072 char *string
; /* Pointer to argument string. */
1073 int alt
= 0; /* Alternate format. */
1074 int space
= 0; /* Use space prefix if no sign is needed. */
1075 int left
= 0; /* Left-justify output. */
1076 int showsign
= 0; /* Always begin with plus or minus sign. */
1077 int group
= 0; /* Print numbers according grouping rules. */
1078 int is_long_double
= 0; /* Argument is long double/ long long int. */
1079 int is_short
= 0; /* Argument is long int. */
1080 int is_long
= 0; /* Argument is short int. */
1081 int is_char
= 0; /* Argument is promoted (unsigned) char. */
1082 int width
= 0; /* Width of output; 0 means none specified. */
1083 int prec
= -1; /* Precision of output; -1 means none specified. */
1084 char pad
= ' '; /* Padding character. */
1087 /* Get current character in format string. */
1088 JUMP (*++f
, step0_jumps
);
1093 JUMP (*++f
, step0_jumps
);
1098 JUMP (*++f
, step0_jumps
);
1104 JUMP (*++f
, step0_jumps
);
1109 JUMP (*++f
, step0_jumps
);
1115 JUMP (*++f
, step0_jumps
);
1117 /* The '\'' flag. */
1121 /* XXX Completely wrong. Use wctob. */
1122 if (grouping
== (const char *) -1)
1124 /* Figure out the thousands separator character. */
1125 if (mbtowc (&thousands_sep
,
1126 _NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
),
1127 strlen (_NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
))) <= 0)
1128 thousands_sep
= (wchar_t)
1129 *_NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
);
1130 grouping
= _NL_CURRENT (LC_NUMERIC
, GROUPING
);
1131 if (*grouping
== '\0' || *grouping
== CHAR_MAX
1132 || thousands_sep
== L
'\0')
1135 JUMP (*++f
, step0_jumps
);
1137 /* Get width from argument. */
1138 LABEL (width_asterics
):
1140 const UCHAR_T
*tmp
; /* Temporary value. */
1143 if (ISDIGIT (*tmp
) && read_int (&tmp
) && *tmp
== L_('$'))
1144 /* The width comes from a positional parameter. */
1147 width
= va_arg (ap
, int);
1149 /* Negative width means left justified. */
1157 JUMP (*f
, step1_jumps
);
1159 /* Given width in format string. */
1161 width
= read_int (&f
);
1163 /* Oh, oh. The argument comes from a positional parameter. */
1165 JUMP (*f
, step1_jumps
);
1171 const UCHAR_T
*tmp
; /* Temporary value. */
1174 if (ISDIGIT (*tmp
) && read_int (&tmp
) > 0 && *tmp
== L_('$'))
1175 /* The precision comes from a positional parameter. */
1178 prec
= va_arg (ap
, int);
1180 /* If the precision is negative the precision is omitted. */
1184 else if (ISDIGIT (*f
))
1185 prec
= read_int (&f
);
1188 JUMP (*f
, step2_jumps
);
1190 /* Process 'h' modifier. There might another 'h' following. */
1193 JUMP (*++f
, step3a_jumps
);
1195 /* Process 'hh' modifier. */
1196 LABEL (mod_halfhalf
):
1199 JUMP (*++f
, step4_jumps
);
1201 /* Process 'l' modifier. There might another 'l' following. */
1204 JUMP (*++f
, step3b_jumps
);
1206 /* Process 'L', 'q', or 'll' modifier. No other modifier is
1207 allowed to follow. */
1208 LABEL (mod_longlong
):
1210 JUMP (*++f
, step4_jumps
);
1213 is_longlong
= sizeof (size_t) > sizeof (unsigned long int);
1214 is_long
= sizeof (size_t) > sizeof (unsigned int);
1215 JUMP (*++f
, step4_jumps
);
1217 LABEL (mod_ptrdiff_t
):
1218 is_longlong
= sizeof (ptrdiff_t) > sizeof (unsigned long int);
1219 is_long
= sizeof (ptrdiff_t) > sizeof (unsigned int);
1220 JUMP (*++f
, step4_jumps
);
1222 LABEL (mod_intmax_t
):
1223 is_longlong
= sizeof (intmax_t) > sizeof (unsigned long int);
1224 is_long
= sizeof (intmax_t) > sizeof (unsigned int);
1225 JUMP (*++f
, step4_jumps
);
1227 /* Process current format. */
1230 process_arg (((struct printf_spec
*) NULL
));
1232 LABEL (form_unknown
):
1233 if (spec
== L_('\0'))
1235 /* The format string ended before the specifier is complete. */
1240 /* If we are in the fast loop force entering the complicated
1245 /* The format is correctly handled. */
1248 /* Look for next format specifier. */
1249 f
= find_spec ((end_of_spec
= ++f
), &mbstate
);
1251 /* Write the following constant string. */
1252 outstring (end_of_spec
, f
- end_of_spec
);
1254 while (*f
!= L_('\0'));
1256 /* Unlock stream and return. */
1259 /* Here starts the more complex loop to handle positional parameters. */
1262 /* Array with information about the needed arguments. This has to
1263 be dynamically extensible. */
1265 size_t nspecs_max
= 32; /* A more or less arbitrary start value. */
1266 struct printf_spec
*specs
1267 = alloca (nspecs_max
* sizeof (struct printf_spec
));
1269 /* The number of arguments the format string requests. This will
1270 determine the size of the array needed to store the argument
1274 union printf_arg
*args_value
;
1276 /* Positional parameters refer to arguments directly. This could
1277 also determine the maximum number of arguments. Track the
1279 size_t max_ref_arg
= 0;
1281 /* Just a counter. */
1285 if (grouping
== (const char *) -1)
1287 /* XXX Use wctob. But this is incompatible for now. */
1288 /* Figure out the thousands separator character. */
1289 if (mbtowc (&thousands_sep
,
1290 _NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
),
1291 strlen (_NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
))) <= 0)
1292 thousands_sep
= (wchar_t) *_NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
);
1293 grouping
= _NL_CURRENT (LC_NUMERIC
, GROUPING
);
1294 if (*grouping
== '\0' || *grouping
== CHAR_MAX
1295 || thousands_sep
== L
'\0')
1299 for (f
= lead_str_end
; *f
!= '\0'; f
= specs
[nspecs
++].next_fmt
)
1301 if (nspecs
>= nspecs_max
)
1303 /* Extend the array of format specifiers. */
1304 struct printf_spec
*old
= specs
;
1307 specs
= alloca (nspecs_max
* sizeof (struct printf_spec
));
1309 if (specs
== &old
[nspecs
])
1310 /* Stack grows up, OLD was the last thing allocated;
1312 nspecs_max
+= nspecs_max
/ 2;
1315 /* Copy the old array's elements to the new space. */
1316 memcpy (specs
, old
, nspecs
* sizeof (struct printf_spec
));
1317 if (old
== &specs
[nspecs
])
1318 /* Stack grows down, OLD was just below the new
1319 SPECS. We can use that space when the new space
1321 nspecs_max
+= nspecs_max
/ 2;
1325 /* Parse the format specifier. */
1326 nargs
+= parse_one_spec (f
, nargs
, &specs
[nspecs
], &max_ref_arg
,
1330 /* Determine the number of arguments the format string consumes. */
1331 nargs
= MAX (nargs
, max_ref_arg
);
1333 /* Allocate memory for the argument descriptions. */
1334 args_type
= alloca (nargs
* sizeof (int));
1335 memset (args_type
, 0, nargs
* sizeof (int));
1336 args_value
= alloca (nargs
* sizeof (union printf_arg
));
1338 /* XXX Could do sanity check here: If any element in ARGS_TYPE is
1339 still zero after this loop, format is invalid. For now we
1340 simply use 0 as the value. */
1342 /* Fill in the types of all the arguments. */
1343 for (cnt
= 0; cnt
< nspecs
; ++cnt
)
1345 /* If the width is determined by an argument this is an int. */
1346 if (specs
[cnt
].width_arg
!= -1)
1347 args_type
[specs
[cnt
].width_arg
] = PA_INT
;
1349 /* If the precision is determined by an argument this is an int. */
1350 if (specs
[cnt
].prec_arg
!= -1)
1351 args_type
[specs
[cnt
].prec_arg
] = PA_INT
;
1353 switch (specs
[cnt
].ndata_args
)
1355 case 0: /* No arguments. */
1357 case 1: /* One argument; we already have the type. */
1358 args_type
[specs
[cnt
].data_arg
] = specs
[cnt
].data_arg_type
;
1361 /* We have more than one argument for this format spec.
1362 We must call the arginfo function again to determine
1364 (void) (*__printf_arginfo_table
[specs
[cnt
].info
.spec
])
1366 specs
[cnt
].ndata_args
, &args_type
[specs
[cnt
].data_arg
]);
1371 /* Now we know all the types and the order. Fill in the argument
1373 for (cnt
= 0; cnt
< nargs
; ++cnt
)
1374 switch (args_type
[cnt
])
1376 #define T(tag, mem, type) \
1378 args_value[cnt].mem = va_arg (ap_save, type); \
1381 T (PA_CHAR
, pa_char
, int); /* Promoted. */
1382 T (PA_WCHAR
, pa_wchar
, wint_t);
1383 T (PA_INT
|PA_FLAG_SHORT
, pa_short_int
, int); /* Promoted. */
1384 T (PA_INT
, pa_int
, int);
1385 T (PA_INT
|PA_FLAG_LONG
, pa_long_int
, long int);
1386 T (PA_INT
|PA_FLAG_LONG_LONG
, pa_long_long_int
, long long int);
1387 T (PA_FLOAT
, pa_float
, double); /* Promoted. */
1388 T (PA_DOUBLE
, pa_double
, double);
1389 T (PA_DOUBLE
|PA_FLAG_LONG_DOUBLE
, pa_long_double
, long double);
1390 T (PA_STRING
, pa_string
, const char *);
1391 T (PA_WSTRING
, pa_wstring
, const wchar_t *);
1392 T (PA_POINTER
, pa_pointer
, void *);
1395 if ((args_type
[cnt
] & PA_FLAG_PTR
) != 0)
1396 args_value
[cnt
].pa_pointer
= va_arg (ap_save
, void *);
1398 args_value
[cnt
].pa_long_double
= 0.0;
1402 /* Now walk through all format specifiers and process them. */
1403 for (; (size_t) nspecs_done
< nspecs
; ++nspecs_done
)
1406 #define REF(Name) &&do2_##Name
1408 #define LABEL(Name) do2_##Name
1414 unsigned long long int longlong
;
1415 unsigned long int word
;
1418 union printf_arg the_arg
;
1419 char *string
; /* Pointer to argument string. */
1421 /* Fill variables from values in struct. */
1422 int alt
= specs
[nspecs_done
].info
.alt
;
1423 int space
= specs
[nspecs_done
].info
.space
;
1424 int left
= specs
[nspecs_done
].info
.left
;
1425 int showsign
= specs
[nspecs_done
].info
.showsign
;
1426 int group
= specs
[nspecs_done
].info
.group
;
1427 int is_long_double
= specs
[nspecs_done
].info
.is_long_double
;
1428 int is_short
= specs
[nspecs_done
].info
.is_short
;
1429 int is_char
= specs
[nspecs_done
].info
.is_char
;
1430 int is_long
= specs
[nspecs_done
].info
.is_long
;
1431 int width
= specs
[nspecs_done
].info
.width
;
1432 int prec
= specs
[nspecs_done
].info
.prec
;
1433 char pad
= specs
[nspecs_done
].info
.pad
;
1434 CHAR_T spec
= specs
[nspecs_done
].info
.spec
;
1436 /* Fill in last information. */
1437 if (specs
[nspecs_done
].width_arg
!= -1)
1439 /* Extract the field width from an argument. */
1440 specs
[nspecs_done
].info
.width
=
1441 args_value
[specs
[nspecs_done
].width_arg
].pa_int
;
1443 if (specs
[nspecs_done
].info
.width
< 0)
1444 /* If the width value is negative left justification is
1445 selected and the value is taken as being positive. */
1447 specs
[nspecs_done
].info
.width
*= -1;
1448 left
= specs
[nspecs_done
].info
.left
= 1;
1450 width
= specs
[nspecs_done
].info
.width
;
1453 if (specs
[nspecs_done
].prec_arg
!= -1)
1455 /* Extract the precision from an argument. */
1456 specs
[nspecs_done
].info
.prec
=
1457 args_value
[specs
[nspecs_done
].prec_arg
].pa_int
;
1459 if (specs
[nspecs_done
].info
.prec
< 0)
1460 /* If the precision is negative the precision is
1462 specs
[nspecs_done
].info
.prec
= -1;
1464 prec
= specs
[nspecs_done
].info
.prec
;
1467 /* Process format specifiers. */
1470 JUMP (spec
, step4_jumps
);
1472 process_arg ((&specs
[nspecs_done
]));
1474 LABEL (form_unknown
):
1476 extern printf_function
**__printf_function_table
;
1478 printf_function
*function
;
1483 (__printf_function_table
== NULL
? NULL
:
1484 __printf_function_table
[specs
[nspecs_done
].info
.spec
]);
1486 if (function
== NULL
)
1487 function
= &printf_unknown
;
1489 ptr
= alloca (specs
[nspecs_done
].ndata_args
1490 * sizeof (const void *));
1492 /* Fill in an array of pointers to the argument values. */
1493 for (i
= 0; i
< specs
[nspecs_done
].ndata_args
; ++i
)
1494 ptr
[i
] = &args_value
[specs
[nspecs_done
].data_arg
+ i
];
1496 /* Call the function. */
1497 function_done
= (*function
) (s
, &specs
[nspecs_done
].info
, ptr
);
1499 /* If an error occurred we don't have information about #
1501 if (function_done
< 0)
1507 done
+= function_done
;
1512 /* Write the following constant string. */
1513 outstring (specs
[nspecs_done
].end_of_fmt
,
1514 specs
[nspecs_done
].next_fmt
1515 - specs
[nspecs_done
].end_of_fmt
);
1520 /* Unlock the stream. */
1522 _IO_funlockfile (s
);
1526 __libc_cleanup_region_end (0);
1533 # ifdef strong_alias
1534 /* This is for glibc. */
1535 strong_alias (_IO_vfprintf
, vfprintf
);
1537 # if defined __ELF__ || defined __GNU_LIBRARY__
1538 # include <gnu-stabs.h>
1540 weak_alias (_IO_vfprintf
, vfprintf
);
1546 /* Handle an unknown format specifier. This prints out a canonicalized
1547 representation of the format spec itself. */
1549 printf_unknown (FILE *s
, const struct printf_info
*info
,
1550 const void *const *args
)
1554 char work_buffer
[BUFSIZ
];
1565 else if (info
->space
)
1569 if (info
->pad
== '0')
1572 if (info
->width
!= 0)
1574 w
= _itoa_word (info
->width
, workend
+ 1, 10, 0);
1575 while (w
<= workend
)
1579 if (info
->prec
!= -1)
1582 w
= _itoa_word (info
->prec
, workend
+ 1, 10, 0);
1583 while (w
<= workend
)
1587 if (info
->spec
!= '\0')
1588 outchar (info
->spec
);
1594 /* Group the digits according to the grouping rules of the current locale.
1595 The interpretation of GROUPING is as in `struct lconv' from <locale.h>. */
1598 group_number (CHAR_T
*w
, CHAR_T
*rear_ptr
, const CHAR_T
*grouping
,
1599 wchar_t thousands_sep
)
1604 /* We treat all negative values like CHAR_MAX. */
1606 if (*grouping
== CHAR_MAX
|| *grouping
<= 0)
1607 /* No grouping should be done. */
1612 /* Copy existing string so that nothing gets overwritten. */
1613 src
= (char *) alloca (rear_ptr
- w
);
1614 s
= (char *) __mempcpy (src
, w
+ 1, rear_ptr
- w
) - 1;
1617 /* Process all characters in the string. */
1622 if (--len
== 0 && s
>= src
)
1624 /* A new group begins. */
1625 *w
-- = thousands_sep
;
1628 if (*grouping
== '\0')
1629 /* The previous grouping repeats ad infinitum. */
1631 else if (*grouping
== CHAR_MAX
1637 /* No further grouping to be done.
1638 Copy the rest of the number. */
1650 /* Helper "class" for `fprintf to unbuffered': creates a temporary buffer. */
1653 struct _IO_FILE_plus _f
;
1654 _IO_FILE
*_put_stream
;
1655 #ifdef _IO_MTSAFE_IO
1661 _IO_helper_overflow (_IO_FILE
*s
, int c
)
1663 _IO_FILE
*target
= ((struct helper_file
*) s
)->_put_stream
;
1664 int used
= s
->_IO_write_ptr
- s
->_IO_write_base
;
1667 _IO_size_t written
= _IO_sputn (target
, s
->_IO_write_base
, used
);
1668 s
->_IO_write_ptr
-= written
;
1673 static const struct _IO_jump_t _IO_helper_jumps
=
1676 JUMP_INIT (finish
, _IO_default_finish
),
1677 JUMP_INIT (overflow
, _IO_helper_overflow
),
1678 JUMP_INIT (underflow
, _IO_default_underflow
),
1679 JUMP_INIT (uflow
, _IO_default_uflow
),
1680 JUMP_INIT (pbackfail
, _IO_default_pbackfail
),
1681 JUMP_INIT (xsputn
, _IO_default_xsputn
),
1682 JUMP_INIT (xsgetn
, _IO_default_xsgetn
),
1683 JUMP_INIT (seekoff
, _IO_default_seekoff
),
1684 JUMP_INIT (seekpos
, _IO_default_seekpos
),
1685 JUMP_INIT (setbuf
, _IO_default_setbuf
),
1686 JUMP_INIT (sync
, _IO_default_sync
),
1687 JUMP_INIT (doallocate
, _IO_default_doallocate
),
1688 JUMP_INIT (read
, _IO_default_read
),
1689 JUMP_INIT (write
, _IO_default_write
),
1690 JUMP_INIT (seek
, _IO_default_seek
),
1691 JUMP_INIT (close
, _IO_default_close
),
1692 JUMP_INIT (stat
, _IO_default_stat
)
1697 buffered_vfprintf (register _IO_FILE
*s
, const CHAR_T
*format
,
1700 char buf
[_IO_BUFSIZ
];
1701 struct helper_file helper
;
1702 register _IO_FILE
*hp
= (_IO_FILE
*) &helper
;
1703 int result
, to_flush
;
1705 /* Initialize helper. */
1706 helper
._put_stream
= s
;
1707 hp
->_IO_write_base
= buf
;
1708 hp
->_IO_write_ptr
= buf
;
1709 hp
->_IO_write_end
= buf
+ sizeof buf
;
1710 hp
->_IO_file_flags
= _IO_MAGIC
|_IO_NO_READS
;
1711 #if _IO_JUMPS_OFFSET
1712 hp
->_vtable_offset
= 0;
1714 #ifdef _IO_MTSAFE_IO
1715 hp
->_lock
= &helper
.lock
;
1716 __libc_lock_init (*hp
->_lock
);
1718 _IO_JUMPS (hp
) = (struct _IO_jump_t
*) &_IO_helper_jumps
;
1720 /* Now print to helper instead. */
1721 result
= _IO_vfprintf (hp
, format
, args
);
1723 /* Now flush anything from the helper to the S. */
1724 if ((to_flush
= hp
->_IO_write_ptr
- hp
->_IO_write_base
) > 0)
1726 if ((int) _IO_sputn (s
, hp
->_IO_write_base
, to_flush
) != to_flush
)
1733 #else /* !USE_IN_LIBIO */
1737 buffered_vfprintf (register FILE *s
, const CHAR_T
*format
, va_list args
)
1742 s
->__bufp
= s
->__buffer
= buf
;
1743 s
->__bufsize
= sizeof buf
;
1744 s
->__put_limit
= s
->__buffer
+ s
->__bufsize
;
1745 s
->__get_limit
= s
->__buffer
;
1747 /* Now use buffer to print. */
1748 result
= vfprintf (s
, format
, args
);
1750 if (fflush (s
) == EOF
)
1752 s
->__buffer
= s
->__bufp
= s
->__get_limit
= s
->__put_limit
= NULL
;
1758 /* Pads string with given number of a specified character.
1759 This code is taken from iopadn.c of the GNU I/O library. */
1761 static const CHAR_T blanks
[PADSIZE
] =
1762 { L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' '),
1763 L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' '), L_(' ') };
1764 static const CHAR_T zeroes
[PADSIZE
] =
1765 { L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0'),
1766 L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0'), L_('0') };
1769 #ifndef COMPILE_WPRINTF
1770 __printf_pad (FILE *s
, char pad
, size_t count
)
1772 __wprintf_pad (FILE *s
, wchar_t pad
, size_t count
)
1775 const CHAR_T
*padptr
;
1778 padptr
= pad
== L_(' ') ? blanks
: zeroes
;
1780 for (i
= count
; i
>= PADSIZE
; i
-= PADSIZE
)
1781 if (PUT (s
, padptr
, PADSIZE
) != PADSIZE
)
1784 if (PUT (s
, padptr
, i
) != i
)
1790 #endif /* USE_IN_LIBIO */