1 /* Copyright (C) 1991-2023 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, see
16 <https://www.gnu.org/licenses/>. */
18 #include <array_length.h>
29 #include <libc-lock.h>
30 #include <sys/param.h>
32 #include <locale/localeinfo.h>
33 #include <grouping_iterator.h>
35 #include <scratch_buffer.h>
37 #include <printf_buffer.h>
38 #include <printf_buffer_to_file.h>
40 /* This code is shared between the standard stdio implementation found
41 in GNU C library and the libio implementation originally found in
44 Beside this it is also shared between the normal and wide character
45 implementation as defined in ISO/IEC 9899:1990/Amendment 1:1995. */
49 #ifdef COMPILE_WPRINTF
53 #define ARGCHECK(S, Format) \
56 /* Check file argument for consistence. */ \
58 if (S->_flags & _IO_NO_WRITES) \
60 S->_flags |= _IO_ERR_SEEN; \
61 __set_errno (EBADF); \
66 __set_errno (EINVAL); \
70 #define UNBUFFERED_P(S) ((S)->_flags & _IO_UNBUFFERED)
72 #if __HAVE_FLOAT128_UNLIKE_LDBL
73 # define PARSE_FLOAT_VA_ARG_EXTENDED(INFO) \
77 && (mode_flags & PRINTF_LDBL_USES_FLOAT128) != 0) \
79 INFO.is_binary128 = 1; \
80 the_arg.pa_float128 = va_arg (ap, _Float128); \
84 PARSE_FLOAT_VA_ARG (INFO); \
89 # define PARSE_FLOAT_VA_ARG_EXTENDED(INFO) \
90 PARSE_FLOAT_VA_ARG (INFO);
93 #define PARSE_FLOAT_VA_ARG(INFO) \
96 INFO.is_binary128 = 0; \
98 the_arg.pa_long_double = va_arg (ap, long double); \
100 the_arg.pa_double = va_arg (ap, double); \
104 #if __HAVE_FLOAT128_UNLIKE_LDBL
105 # define SETUP_FLOAT128_INFO(INFO) \
108 if ((mode_flags & PRINTF_LDBL_USES_FLOAT128) != 0) \
109 INFO.is_binary128 = is_long_double; \
111 INFO.is_binary128 = 0; \
115 # define SETUP_FLOAT128_INFO(INFO) \
118 INFO.is_binary128 = 0; \
123 #ifndef COMPILE_WPRINTF
124 # include "printf_buffer-char.h"
125 # define vfprintf __vfprintf_internal
126 # define OTHER_CHAR_T wchar_t
127 # define UCHAR_T unsigned char
129 typedef const char *THOUSANDS_SEP_T
;
131 # define ISDIGIT(Ch) ((unsigned int) ((Ch) - '0') < 10)
132 # define STR_LEN(Str) strlen (Str)
134 # define ORIENT if (_IO_vtable_offset (s) == 0 && _IO_fwide (s, -1) != -1)\
136 # define CONVERT_FROM_OTHER_STRING __wcsrtombs
138 # include "printf_buffer-wchar_t.h"
139 # define vfprintf __vfwprintf_internal
140 # define OTHER_CHAR_T char
141 /* This is a hack!!! There should be a type uwchar_t. */
142 # define UCHAR_T unsigned int /* uwchar_t */
143 # define INT_T wint_t
144 typedef wchar_t THOUSANDS_SEP_T
;
145 # define L_(Str) L##Str
146 # define ISDIGIT(Ch) ((unsigned int) ((Ch) - L'0') < 10)
147 # define STR_LEN(Str) __wcslen (Str)
151 # define ORIENT if (_IO_fwide (s, 1) != 1) return -1
152 # define CONVERT_FROM_OTHER_STRING __mbsrtowcs
155 # define _itoa(Val, Buf, Base, Case) _itowa (Val, Buf, Base, Case)
156 # define _itoa_word(Val, Buf, Base, Case) _itowa_word (Val, Buf, Base, Case)
161 /* Include the shared code for parsing the format string. */
162 #include "printf-parse.h"
165 /* Write the string SRC to S. If PREC is non-negative, write at most
166 PREC bytes. If LEFT is true, perform left justification. */
168 outstring_converted_wide_string (struct Xprintf_buffer
*target
,
169 const OTHER_CHAR_T
*src
, int prec
,
170 int width
, bool left
)
172 /* Use a small buffer to combine processing of multiple characters.
173 CONVERT_FROM_OTHER_STRING expects the buffer size in (wide)
174 characters, and buf_length counts that. */
175 enum { buf_length
= 256 / sizeof (CHAR_T
) };
176 CHAR_T buf
[buf_length
];
177 _Static_assert (sizeof (buf
) > MB_LEN_MAX
,
178 "buffer is large enough for a single multi-byte character");
180 /* Add the initial padding if needed. */
181 if (width
> 0 && !left
)
183 /* Make a first pass to find the output width, so that we can
184 add the required padding. */
185 mbstate_t mbstate
= { 0 };
186 const OTHER_CHAR_T
*src_copy
= src
;
187 size_t total_written
;
189 total_written
= CONVERT_FROM_OTHER_STRING
190 (NULL
, &src_copy
, 0, &mbstate
);
193 /* The source might not be null-terminated. Enforce the
194 limit manually, based on the output length. */
197 while (limit
> 0 && src_copy
!= NULL
)
199 size_t write_limit
= buf_length
;
200 if (write_limit
> limit
)
202 size_t written
= CONVERT_FROM_OTHER_STRING
203 (buf
, &src_copy
, write_limit
, &mbstate
);
204 if (written
== (size_t) -1)
206 Xprintf_buffer_mark_failed (target
);
211 total_written
+= written
;
216 /* Output initial padding. */
217 Xprintf_buffer_pad (target
, L_(' '), width
- total_written
);
218 if (Xprintf_buffer_has_failed (target
))
222 /* Convert the input string, piece by piece. */
223 size_t total_written
= 0;
225 mbstate_t mbstate
= { 0 };
226 /* If prec is negative, remaining is not decremented, otherwise,
227 it serves as the write limit. */
228 size_t remaining
= -1;
231 while (remaining
> 0 && src
!= NULL
)
233 size_t write_limit
= buf_length
;
234 if (remaining
< write_limit
)
235 write_limit
= remaining
;
236 size_t written
= CONVERT_FROM_OTHER_STRING
237 (buf
, &src
, write_limit
, &mbstate
);
238 if (written
== (size_t) -1)
240 Xprintf_buffer_mark_failed (target
);
245 Xprintf_buffer_write (target
, buf
, written
);
246 total_written
+= written
;
248 remaining
-= written
;
252 /* Add final padding. */
253 if (width
> 0 && left
)
254 Xprintf_buffer_pad (target
, L_(' '), width
- total_written
);
257 /* Calls __printf_fp or __printf_fphex based on the value of the
258 format specifier INFO->spec. */
260 __printf_fp_spec (struct Xprintf_buffer
*target
,
261 const struct printf_info
*info
, const void *const *args
)
263 if (info
->spec
== 'a' || info
->spec
== 'A')
264 Xprintf (fphex_l_buffer
) (target
, _NL_CURRENT_LOCALE
, info
, args
);
266 Xprintf (fp_l_buffer
) (target
, _NL_CURRENT_LOCALE
, info
, args
);
269 /* For handling long_double and longlong we use the same flag. If
270 `long' and `long long' are effectively the same type define it to
272 #if LONG_MAX == LONG_LONG_MAX
273 # define is_longlong 0
275 # define is_longlong is_long_double
278 /* If `long' and `int' is effectively the same type we don't have to
279 handle `long separately. */
280 #if INT_MAX == LONG_MAX
281 # define is_long_num 0
283 # define is_long_num is_long
287 /* Global constants. */
288 static const CHAR_T null
[] = L_("(null)");
290 /* Size of the work_buffer variable (in characters, not bytes. */
291 enum { WORK_BUFFER_SIZE
= 1000 / sizeof (CHAR_T
) };
293 /* This table maps a character into a number representing a class. In
294 each step there is a destination label for each class. */
295 static const uint8_t jump_table
[] =
297 /* ' ' */ 1, 0, 0, /* '#' */ 4,
298 0, /* '%' */ 14, 0, /* '\''*/ 6,
299 0, 0, /* '*' */ 7, /* '+' */ 2,
300 0, /* '-' */ 3, /* '.' */ 9, 0,
301 /* '0' */ 5, /* '1' */ 8, /* '2' */ 8, /* '3' */ 8,
302 /* '4' */ 8, /* '5' */ 8, /* '6' */ 8, /* '7' */ 8,
303 /* '8' */ 8, /* '9' */ 8, 0, 0,
305 0, /* 'A' */ 26, /* 'B' */ 30, /* 'C' */ 25,
306 0, /* 'E' */ 19, /* F */ 19, /* 'G' */ 19,
307 0, /* 'I' */ 29, 0, 0,
308 /* 'L' */ 12, 0, 0, 0,
309 0, 0, 0, /* 'S' */ 21,
311 /* 'X' */ 18, 0, /* 'Z' */ 13, 0,
313 0, /* 'a' */ 26, /* 'b' */ 30, /* 'c' */ 20,
314 /* 'd' */ 15, /* 'e' */ 19, /* 'f' */ 19, /* 'g' */ 19,
315 /* 'h' */ 10, /* 'i' */ 15, /* 'j' */ 28, 0,
316 /* 'l' */ 11, /* 'm' */ 24, /* 'n' */ 23, /* 'o' */ 17,
317 /* 'p' */ 22, /* 'q' */ 12, 0, /* 's' */ 21,
318 /* 't' */ 27, /* 'u' */ 16, 0, 0,
319 /* 'x' */ 18, 0, /* 'z' */ 13
322 #define NOT_IN_JUMP_RANGE(Ch) ((Ch) < L_(' ') || (Ch) > L_('z'))
323 #define CHAR_CLASS(Ch) (jump_table[(INT_T) (Ch) - L_(' ')])
324 #define LABEL(Name) do_##Name
326 /* 'int' is enough and it saves some space on 64 bit systems. */
327 # define JUMP_TABLE_TYPE const int
328 # define JUMP_TABLE_BASE_LABEL do_form_unknown
329 # define REF(Name) &&do_##Name - &&JUMP_TABLE_BASE_LABEL
330 # define JUMP(ChExpr, table) \
336 offset = NOT_IN_JUMP_RANGE (spec) ? REF (form_unknown) \
337 : table[CHAR_CLASS (spec)]; \
338 ptr = &&JUMP_TABLE_BASE_LABEL + offset; \
343 # define JUMP_TABLE_TYPE const void *const
344 # define REF(Name) &&do_##Name
345 # define JUMP(ChExpr, table) \
350 ptr = NOT_IN_JUMP_RANGE (spec) ? REF (form_unknown) \
351 : table[CHAR_CLASS (spec)]; \
357 #define STEP0_3_TABLE \
358 /* Step 0: at the beginning. */ \
359 static JUMP_TABLE_TYPE step0_jumps[31] = \
361 REF (form_unknown), \
362 REF (flag_space), /* for ' ' */ \
363 REF (flag_plus), /* for '+' */ \
364 REF (flag_minus), /* for '-' */ \
365 REF (flag_hash), /* for '<hash>' */ \
366 REF (flag_zero), /* for '0' */ \
367 REF (flag_quote), /* for '\'' */ \
368 REF (width_asterics), /* for '*' */ \
369 REF (width), /* for '1'...'9' */ \
370 REF (precision), /* 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 (flag_i18n), /* for 'I' */ \
391 REF (form_binary), /* for 'B', 'b' */ \
393 /* Step 1: after processing width. */ \
394 static JUMP_TABLE_TYPE step1_jumps[31] = \
396 REF (form_unknown), \
397 REF (form_unknown), /* for ' ' */ \
398 REF (form_unknown), /* for '+' */ \
399 REF (form_unknown), /* for '-' */ \
400 REF (form_unknown), /* for '<hash>' */ \
401 REF (form_unknown), /* for '0' */ \
402 REF (form_unknown), /* for '\'' */ \
403 REF (form_unknown), /* for '*' */ \
404 REF (form_unknown), /* for '1'...'9' */ \
405 REF (precision), /* for '.' */ \
406 REF (mod_half), /* for 'h' */ \
407 REF (mod_long), /* for 'l' */ \
408 REF (mod_longlong), /* for 'L', 'q' */ \
409 REF (mod_size_t), /* for 'z', 'Z' */ \
410 REF (form_percent), /* for '%' */ \
411 REF (form_integer), /* for 'd', 'i' */ \
412 REF (form_unsigned), /* for 'u' */ \
413 REF (form_octal), /* for 'o' */ \
414 REF (form_hexa), /* for 'X', 'x' */ \
415 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
416 REF (form_character), /* for 'c' */ \
417 REF (form_string), /* for 's', 'S' */ \
418 REF (form_pointer), /* for 'p' */ \
419 REF (form_number), /* for 'n' */ \
420 REF (form_strerror), /* for 'm' */ \
421 REF (form_wcharacter), /* for 'C' */ \
422 REF (form_floathex), /* for 'A', 'a' */ \
423 REF (mod_ptrdiff_t), /* for 't' */ \
424 REF (mod_intmax_t), /* for 'j' */ \
425 REF (form_unknown), /* for 'I' */ \
426 REF (form_binary), /* for 'B', 'b' */ \
428 /* Step 2: after processing precision. */ \
429 static JUMP_TABLE_TYPE step2_jumps[31] = \
431 REF (form_unknown), \
432 REF (form_unknown), /* for ' ' */ \
433 REF (form_unknown), /* for '+' */ \
434 REF (form_unknown), /* for '-' */ \
435 REF (form_unknown), /* for '<hash>' */ \
436 REF (form_unknown), /* for '0' */ \
437 REF (form_unknown), /* for '\'' */ \
438 REF (form_unknown), /* for '*' */ \
439 REF (form_unknown), /* for '1'...'9' */ \
440 REF (form_unknown), /* for '.' */ \
441 REF (mod_half), /* for 'h' */ \
442 REF (mod_long), /* for 'l' */ \
443 REF (mod_longlong), /* for 'L', 'q' */ \
444 REF (mod_size_t), /* for 'z', 'Z' */ \
445 REF (form_percent), /* for '%' */ \
446 REF (form_integer), /* for 'd', 'i' */ \
447 REF (form_unsigned), /* for 'u' */ \
448 REF (form_octal), /* for 'o' */ \
449 REF (form_hexa), /* for 'X', 'x' */ \
450 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
451 REF (form_character), /* for 'c' */ \
452 REF (form_string), /* for 's', 'S' */ \
453 REF (form_pointer), /* for 'p' */ \
454 REF (form_number), /* for 'n' */ \
455 REF (form_strerror), /* for 'm' */ \
456 REF (form_wcharacter), /* for 'C' */ \
457 REF (form_floathex), /* for 'A', 'a' */ \
458 REF (mod_ptrdiff_t), /* for 't' */ \
459 REF (mod_intmax_t), /* for 'j' */ \
460 REF (form_unknown), /* for 'I' */ \
461 REF (form_binary), /* for 'B', 'b' */ \
463 /* Step 3a: after processing first 'h' modifier. */ \
464 static JUMP_TABLE_TYPE step3a_jumps[31] = \
466 REF (form_unknown), \
467 REF (form_unknown), /* for ' ' */ \
468 REF (form_unknown), /* for '+' */ \
469 REF (form_unknown), /* for '-' */ \
470 REF (form_unknown), /* for '<hash>' */ \
471 REF (form_unknown), /* for '0' */ \
472 REF (form_unknown), /* for '\'' */ \
473 REF (form_unknown), /* for '*' */ \
474 REF (form_unknown), /* for '1'...'9' */ \
475 REF (form_unknown), /* for '.' */ \
476 REF (mod_halfhalf), /* for 'h' */ \
477 REF (form_unknown), /* for 'l' */ \
478 REF (form_unknown), /* for 'L', 'q' */ \
479 REF (form_unknown), /* for 'z', 'Z' */ \
480 REF (form_percent), /* for '%' */ \
481 REF (form_integer), /* for 'd', 'i' */ \
482 REF (form_unsigned), /* for 'u' */ \
483 REF (form_octal), /* for 'o' */ \
484 REF (form_hexa), /* for 'X', 'x' */ \
485 REF (form_unknown), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
486 REF (form_unknown), /* for 'c' */ \
487 REF (form_unknown), /* for 's', 'S' */ \
488 REF (form_unknown), /* for 'p' */ \
489 REF (form_number), /* for 'n' */ \
490 REF (form_unknown), /* for 'm' */ \
491 REF (form_unknown), /* for 'C' */ \
492 REF (form_unknown), /* for 'A', 'a' */ \
493 REF (form_unknown), /* for 't' */ \
494 REF (form_unknown), /* for 'j' */ \
495 REF (form_unknown), /* for 'I' */ \
496 REF (form_binary), /* for 'B', 'b' */ \
498 /* Step 3b: after processing first 'l' modifier. */ \
499 static JUMP_TABLE_TYPE step3b_jumps[31] = \
501 REF (form_unknown), \
502 REF (form_unknown), /* for ' ' */ \
503 REF (form_unknown), /* for '+' */ \
504 REF (form_unknown), /* for '-' */ \
505 REF (form_unknown), /* for '<hash>' */ \
506 REF (form_unknown), /* for '0' */ \
507 REF (form_unknown), /* for '\'' */ \
508 REF (form_unknown), /* for '*' */ \
509 REF (form_unknown), /* for '1'...'9' */ \
510 REF (form_unknown), /* for '.' */ \
511 REF (form_unknown), /* for 'h' */ \
512 REF (mod_longlong), /* for 'l' */ \
513 REF (form_unknown), /* for 'L', 'q' */ \
514 REF (form_unknown), /* for 'z', 'Z' */ \
515 REF (form_percent), /* for '%' */ \
516 REF (form_integer), /* for 'd', 'i' */ \
517 REF (form_unsigned), /* for 'u' */ \
518 REF (form_octal), /* for 'o' */ \
519 REF (form_hexa), /* for 'X', 'x' */ \
520 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
521 REF (form_character), /* for 'c' */ \
522 REF (form_string), /* for 's', 'S' */ \
523 REF (form_pointer), /* for 'p' */ \
524 REF (form_number), /* for 'n' */ \
525 REF (form_strerror), /* for 'm' */ \
526 REF (form_wcharacter), /* for 'C' */ \
527 REF (form_floathex), /* for 'A', 'a' */ \
528 REF (form_unknown), /* for 't' */ \
529 REF (form_unknown), /* for 'j' */ \
530 REF (form_unknown), /* for 'I' */ \
531 REF (form_binary), /* for 'B', 'b' */ \
534 #define STEP4_TABLE \
535 /* Step 4: processing format specifier. */ \
536 static JUMP_TABLE_TYPE step4_jumps[31] = \
538 REF (form_unknown), \
539 REF (form_unknown), /* for ' ' */ \
540 REF (form_unknown), /* for '+' */ \
541 REF (form_unknown), /* for '-' */ \
542 REF (form_unknown), /* for '<hash>' */ \
543 REF (form_unknown), /* for '0' */ \
544 REF (form_unknown), /* for '\'' */ \
545 REF (form_unknown), /* for '*' */ \
546 REF (form_unknown), /* for '1'...'9' */ \
547 REF (form_unknown), /* for '.' */ \
548 REF (form_unknown), /* for 'h' */ \
549 REF (form_unknown), /* for 'l' */ \
550 REF (form_unknown), /* for 'L', 'q' */ \
551 REF (form_unknown), /* for 'z', 'Z' */ \
552 REF (form_percent), /* for '%' */ \
553 REF (form_integer), /* for 'd', 'i' */ \
554 REF (form_unsigned), /* for 'u' */ \
555 REF (form_octal), /* for 'o' */ \
556 REF (form_hexa), /* for 'X', 'x' */ \
557 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
558 REF (form_character), /* for 'c' */ \
559 REF (form_string), /* for 's', 'S' */ \
560 REF (form_pointer), /* for 'p' */ \
561 REF (form_number), /* for 'n' */ \
562 REF (form_strerror), /* for 'm' */ \
563 REF (form_wcharacter), /* for 'C' */ \
564 REF (form_floathex), /* for 'A', 'a' */ \
565 REF (form_unknown), /* for 't' */ \
566 REF (form_unknown), /* for 'j' */ \
567 REF (form_unknown), /* for 'I' */ \
568 REF (form_binary), /* for 'B', 'b' */ \
571 /* Handle positional format specifiers. */
572 static void printf_positional (struct Xprintf_buffer
*buf
,
573 const CHAR_T
*format
, int readonly_format
,
574 va_list ap
, va_list *ap_savep
,
575 int nspecs_done
, const UCHAR_T
*lead_str_end
,
576 CHAR_T
*work_buffer
, int save_errno
,
577 const char *grouping
,
578 THOUSANDS_SEP_T thousands_sep
,
579 unsigned int mode_flags
);
581 /* Handle unknown format specifier. */
582 static void printf_unknown (struct Xprintf_buffer
*,
583 const struct printf_info
*) __THROW
;
585 static void group_number (struct Xprintf_buffer
*buf
,
586 struct grouping_iterator
*iter
,
587 CHAR_T
*from
, CHAR_T
*to
,
588 THOUSANDS_SEP_T thousands_sep
, bool i18n
);
590 /* The buffer-based function itself. */
592 Xprintf_buffer (struct Xprintf_buffer
*buf
, const CHAR_T
*format
,
593 va_list ap
, unsigned int mode_flags
)
595 /* The character used as thousands separator. */
596 THOUSANDS_SEP_T thousands_sep
= 0;
598 /* The string describing the size of groups of digits. */
599 const char *grouping
;
601 /* Current character in format string. */
604 /* End of leading constant string. */
605 const UCHAR_T
*lead_str_end
;
607 /* Points to next format specifier. */
608 const UCHAR_T
*end_of_spec
;
610 /* Buffer intermediate results. */
611 CHAR_T work_buffer
[WORK_BUFFER_SIZE
];
614 /* We have to save the original argument pointer. */
617 /* Count number of specifiers we already processed. */
620 /* For the %m format we may need the current `errno' value. */
621 int save_errno
= errno
;
623 /* 1 if format is in read-only memory, -1 if it is in writable memory,
625 int readonly_format
= 0;
627 /* Initialize local variables. */
628 grouping
= (const char *) -1;
630 /* This macro will be available soon in gcc's <stdarg.h>. We need it
631 since on some systems `va_list' is not an integral type. */
632 __va_copy (ap_save
, ap
);
638 #ifdef COMPILE_WPRINTF
639 /* Find the first format specifier. */
640 f
= lead_str_end
= __find_specwc ((const UCHAR_T
*) format
);
642 /* Find the first format specifier. */
643 f
= lead_str_end
= __find_specmb ((const UCHAR_T
*) format
);
646 /* Write the literal text before the first format. */
647 Xprintf_buffer_write (buf
, format
,
648 lead_str_end
- (const UCHAR_T
*) format
);
649 if (Xprintf_buffer_has_failed (buf
))
652 /* If we only have to print a simple string, return now. */
656 /* Use the slow path in case any printf handler is registered. */
657 if (__glibc_unlikely (__printf_function_table
!= NULL
658 || __printf_modifier_table
!= NULL
659 || __printf_va_arg_table
!= NULL
))
662 /* Process whole format string. */
668 int is_negative
; /* Flag for negative number. */
671 unsigned long long int longlong
;
672 unsigned long int word
;
675 union printf_arg the_arg
;
676 CHAR_T
*string
; /* Pointer to argument string. */
677 int alt
= 0; /* Alternate format. */
678 int space
= 0; /* Use space prefix if no sign is needed. */
679 int left
= 0; /* Left-justify output. */
680 int showsign
= 0; /* Always begin with plus or minus sign. */
681 int group
= 0; /* Print numbers according grouping rules. */
682 /* Argument is long double/long long int. Only used if
683 double/long double or long int/long long int are distinct. */
684 int is_long_double
__attribute__ ((unused
)) = 0;
685 int is_short
= 0; /* Argument is short int. */
686 int is_long
= 0; /* Argument is long int. */
687 int is_char
= 0; /* Argument is promoted (unsigned) char. */
688 int width
= 0; /* Width of output; 0 means none specified. */
689 int prec
= -1; /* Precision of output; -1 means none specified. */
690 /* This flag is set by the 'I' modifier and selects the use of the
691 `outdigits' as determined by the current locale. */
692 int use_outdigits
= 0;
693 UCHAR_T pad
= L_(' ');/* Padding character. */
696 workend
= work_buffer
+ WORK_BUFFER_SIZE
;
698 /* Get current character in format string. */
699 JUMP (*++f
, step0_jumps
);
704 JUMP (*++f
, step0_jumps
);
709 JUMP (*++f
, step0_jumps
);
715 JUMP (*++f
, step0_jumps
);
720 JUMP (*++f
, step0_jumps
);
726 JUMP (*++f
, step0_jumps
);
732 if (grouping
== (const char *) -1)
734 #ifdef COMPILE_WPRINTF
735 thousands_sep
= _NL_CURRENT_WORD (LC_NUMERIC
,
736 _NL_NUMERIC_THOUSANDS_SEP_WC
);
738 thousands_sep
= _NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
);
741 grouping
= _NL_CURRENT (LC_NUMERIC
, GROUPING
);
742 if (*grouping
== '\0' || *grouping
== CHAR_MAX
743 #ifdef COMPILE_WPRINTF
744 || thousands_sep
== L
'\0'
746 || *thousands_sep
== '\0'
751 JUMP (*++f
, step0_jumps
);
755 JUMP (*++f
, step0_jumps
);
757 /* Get width from argument. */
758 LABEL (width_asterics
):
760 const UCHAR_T
*tmp
; /* Temporary value. */
765 int pos
= read_int (&tmp
);
769 __set_errno (EOVERFLOW
);
770 Xprintf_buffer_mark_failed (buf
);
774 if (pos
&& *tmp
== L_('$'))
775 /* The width comes from a positional parameter. */
778 width
= va_arg (ap
, int);
780 /* Negative width means left justified. */
788 JUMP (*f
, step1_jumps
);
790 /* Given width in format string. */
792 width
= read_int (&f
);
794 if (__glibc_unlikely (width
== -1))
796 __set_errno (EOVERFLOW
);
797 Xprintf_buffer_mark_failed (buf
);
802 /* Oh, oh. The argument comes from a positional parameter. */
804 JUMP (*f
, step1_jumps
);
810 const UCHAR_T
*tmp
; /* Temporary value. */
815 int pos
= read_int (&tmp
);
819 __set_errno (EOVERFLOW
);
820 Xprintf_buffer_mark_failed (buf
);
824 if (pos
&& *tmp
== L_('$'))
825 /* The precision comes from a positional parameter. */
828 prec
= va_arg (ap
, int);
830 /* If the precision is negative the precision is omitted. */
834 else if (ISDIGIT (*f
))
836 prec
= read_int (&f
);
838 /* The precision was specified in this case as an extremely
839 large positive value. */
842 __set_errno (EOVERFLOW
);
843 Xprintf_buffer_mark_failed (buf
);
849 JUMP (*f
, step2_jumps
);
851 /* Process 'h' modifier. There might another 'h' following. */
854 JUMP (*++f
, step3a_jumps
);
856 /* Process 'hh' modifier. */
857 LABEL (mod_halfhalf
):
860 JUMP (*++f
, step4_jumps
);
862 /* Process 'l' modifier. There might another 'l' following. */
865 JUMP (*++f
, step3b_jumps
);
867 /* Process 'L', 'q', or 'll' modifier. No other modifier is
868 allowed to follow. */
869 LABEL (mod_longlong
):
872 JUMP (*++f
, step4_jumps
);
875 is_long_double
= sizeof (size_t) > sizeof (unsigned long int);
876 is_long
= sizeof (size_t) > sizeof (unsigned int);
877 JUMP (*++f
, step4_jumps
);
879 LABEL (mod_ptrdiff_t
):
880 is_long_double
= sizeof (ptrdiff_t) > sizeof (unsigned long int);
881 is_long
= sizeof (ptrdiff_t) > sizeof (unsigned int);
882 JUMP (*++f
, step4_jumps
);
884 LABEL (mod_intmax_t
):
885 is_long_double
= sizeof (intmax_t) > sizeof (unsigned long int);
886 is_long
= sizeof (intmax_t) > sizeof (unsigned int);
887 JUMP (*++f
, step4_jumps
);
889 /* Process current format. */
892 #define process_arg_int() va_arg (ap, int)
893 #define process_arg_long_int() va_arg (ap, long int)
894 #define process_arg_long_long_int() va_arg (ap, long long int)
895 #define process_arg_pointer() va_arg (ap, void *)
896 #define process_arg_string() va_arg (ap, const char *)
897 #define process_arg_unsigned_int() va_arg (ap, unsigned int)
898 #define process_arg_unsigned_long_int() va_arg (ap, unsigned long int)
899 #define process_arg_unsigned_long_long_int() va_arg (ap, unsigned long long int)
900 #define process_arg_wchar_t() va_arg (ap, wchar_t)
901 #define process_arg_wstring() va_arg (ap, const wchar_t *)
902 #include "vfprintf-process-arg.c"
903 #undef process_arg_int
904 #undef process_arg_long_int
905 #undef process_arg_long_long_int
906 #undef process_arg_pointer
907 #undef process_arg_string
908 #undef process_arg_unsigned_int
909 #undef process_arg_unsigned_long_int
910 #undef process_arg_unsigned_long_long_int
911 #undef process_arg_wchar_t
912 #undef process_arg_wstring
915 LABEL (form_floathex
):
917 if (__glibc_unlikely ((mode_flags
& PRINTF_LDBL_IS_DBL
) != 0))
920 struct printf_info info
=
925 .is_long_double
= is_long_double
,
926 .is_short
= is_short
,
931 .showsign
= showsign
,
935 .i18n
= use_outdigits
,
936 .wide
= sizeof (CHAR_T
) != 1,
940 PARSE_FLOAT_VA_ARG_EXTENDED (info
);
941 const void *ptr
= &the_arg
;
943 __printf_fp_spec (buf
, &info
, &ptr
);
947 LABEL (form_unknown
):
948 if (spec
== L_('\0'))
950 /* The format string ended before the specifier is complete. */
951 __set_errno (EINVAL
);
952 Xprintf_buffer_mark_failed (buf
);
956 /* If we are in the fast loop force entering the complicated
961 /* The format is correctly handled. */
964 /* Look for next format specifier. */
965 #ifdef COMPILE_WPRINTF
966 f
= __find_specwc ((end_of_spec
= ++f
));
968 f
= __find_specmb ((end_of_spec
= ++f
));
971 /* Write the following constant string. */
972 Xprintf_buffer_write (buf
, (const CHAR_T
*) end_of_spec
,
975 while (*f
!= L_('\0') && !Xprintf_buffer_has_failed (buf
));
978 /* printf_positional performs cleanup under its all_done label, so
979 vfprintf-process-arg.c uses it for this function and
980 printf_positional below. */
983 /* Hand off processing for positional parameters. */
985 printf_positional (buf
, format
, readonly_format
, ap
, &ap_save
,
986 nspecs_done
, lead_str_end
, work_buffer
,
987 save_errno
, grouping
, thousands_sep
, mode_flags
);
991 printf_positional (struct Xprintf_buffer
* buf
, const CHAR_T
*format
,
993 va_list ap
, va_list *ap_savep
, int nspecs_done
,
994 const UCHAR_T
*lead_str_end
,
995 CHAR_T
*work_buffer
, int save_errno
,
996 const char *grouping
, THOUSANDS_SEP_T thousands_sep
,
997 unsigned int mode_flags
)
999 /* For positional argument handling. */
1000 struct scratch_buffer specsbuf
;
1001 scratch_buffer_init (&specsbuf
);
1002 struct printf_spec
*specs
= specsbuf
.data
;
1003 size_t specs_limit
= specsbuf
.length
/ sizeof (specs
[0]);
1005 /* Used as a backing store for args_value, args_size, args_type
1007 struct scratch_buffer argsbuf
;
1008 scratch_buffer_init (&argsbuf
);
1010 /* Array with information about the needed arguments. This has to
1011 be dynamically extensible. */
1014 /* The number of arguments the format string requests. This will
1015 determine the size of the array needed to store the argument
1019 /* Positional parameters refer to arguments directly. This could
1020 also determine the maximum number of arguments. Track the
1022 size_t max_ref_arg
= 0;
1024 /* Just a counter. */
1027 if (grouping
== (const char *) -1)
1029 #ifdef COMPILE_WPRINTF
1030 thousands_sep
= _NL_CURRENT_WORD (LC_NUMERIC
,
1031 _NL_NUMERIC_THOUSANDS_SEP_WC
);
1033 thousands_sep
= _NL_CURRENT (LC_NUMERIC
, THOUSANDS_SEP
);
1036 grouping
= _NL_CURRENT (LC_NUMERIC
, GROUPING
);
1037 if (*grouping
== '\0' || *grouping
== CHAR_MAX
)
1041 for (const UCHAR_T
*f
= lead_str_end
; *f
!= L_('\0');
1042 f
= specs
[nspecs
++].next_fmt
)
1044 if (nspecs
== specs_limit
)
1046 if (!scratch_buffer_grow_preserve (&specsbuf
))
1048 Xprintf_buffer_mark_failed (buf
);
1051 specs
= specsbuf
.data
;
1052 specs_limit
= specsbuf
.length
/ sizeof (specs
[0]);
1055 /* Parse the format specifier. */
1056 #ifdef COMPILE_WPRINTF
1057 nargs
+= __parse_one_specwc (f
, nargs
, &specs
[nspecs
], &max_ref_arg
);
1059 nargs
+= __parse_one_specmb (f
, nargs
, &specs
[nspecs
], &max_ref_arg
);
1063 /* Determine the number of arguments the format string consumes. */
1064 nargs
= MAX (nargs
, max_ref_arg
);
1066 union printf_arg
*args_value
;
1070 /* Calculate total size needed to represent a single argument
1071 across all three argument-related arrays. */
1072 size_t bytes_per_arg
1073 = sizeof (*args_value
) + sizeof (*args_size
) + sizeof (*args_type
);
1074 if (!scratch_buffer_set_array_size (&argsbuf
, nargs
, bytes_per_arg
))
1076 Xprintf_buffer_mark_failed (buf
);
1079 args_value
= argsbuf
.data
;
1080 /* Set up the remaining two arrays to each point past the end of
1081 the prior array, since space for all three has been allocated
1083 args_size
= &args_value
[nargs
].pa_int
;
1084 args_type
= &args_size
[nargs
];
1085 memset (args_type
, (mode_flags
& PRINTF_FORTIFY
) != 0 ? '\xff' : '\0',
1086 nargs
* sizeof (*args_type
));
1089 /* XXX Could do sanity check here: If any element in ARGS_TYPE is
1090 still zero after this loop, format is invalid. For now we
1091 simply use 0 as the value. */
1093 /* Fill in the types of all the arguments. */
1094 for (cnt
= 0; cnt
< nspecs
; ++cnt
)
1096 /* If the width is determined by an argument this is an int. */
1097 if (specs
[cnt
].width_arg
!= -1)
1098 args_type
[specs
[cnt
].width_arg
] = PA_INT
;
1100 /* If the precision is determined by an argument this is an int. */
1101 if (specs
[cnt
].prec_arg
!= -1)
1102 args_type
[specs
[cnt
].prec_arg
] = PA_INT
;
1104 switch (specs
[cnt
].ndata_args
)
1106 case 0: /* No arguments. */
1108 case 1: /* One argument; we already have the
1110 args_type
[specs
[cnt
].data_arg
] = specs
[cnt
].data_arg_type
;
1111 args_size
[specs
[cnt
].data_arg
] = specs
[cnt
].size
;
1114 /* We have more than one argument for this format spec.
1115 We must call the arginfo function again to determine
1117 (void) (*__printf_arginfo_table
[specs
[cnt
].info
.spec
])
1119 specs
[cnt
].ndata_args
, &args_type
[specs
[cnt
].data_arg
],
1120 &args_size
[specs
[cnt
].data_arg
]);
1125 /* Now we know all the types and the order. Fill in the argument
1127 for (cnt
= 0; cnt
< nargs
; ++cnt
)
1128 switch (args_type
[cnt
])
1130 #define T(tag, mem, type) \
1132 args_value[cnt].mem = va_arg (*ap_savep, type); \
1135 T (PA_WCHAR
, pa_wchar
, wint_t);
1136 case PA_CHAR
: /* Promoted. */
1137 case PA_INT
|PA_FLAG_SHORT
: /* Promoted. */
1138 #if LONG_MAX == INT_MAX
1139 case PA_INT
|PA_FLAG_LONG
:
1141 T (PA_INT
, pa_int
, int);
1142 #if LONG_MAX == LONG_LONG_MAX
1143 case PA_INT
|PA_FLAG_LONG
:
1145 T (PA_INT
|PA_FLAG_LONG_LONG
, pa_long_long_int
, long long int);
1146 #if LONG_MAX != INT_MAX && LONG_MAX != LONG_LONG_MAX
1149 case PA_FLOAT
: /* Promoted. */
1150 T (PA_DOUBLE
, pa_double
, double);
1151 case PA_DOUBLE
|PA_FLAG_LONG_DOUBLE
:
1152 if (__glibc_unlikely ((mode_flags
& PRINTF_LDBL_IS_DBL
) != 0))
1154 args_value
[cnt
].pa_double
= va_arg (*ap_savep
, double);
1155 args_type
[cnt
] &= ~PA_FLAG_LONG_DOUBLE
;
1157 #if __HAVE_FLOAT128_UNLIKE_LDBL
1158 else if ((mode_flags
& PRINTF_LDBL_USES_FLOAT128
) != 0)
1159 args_value
[cnt
].pa_float128
= va_arg (*ap_savep
, _Float128
);
1162 args_value
[cnt
].pa_long_double
= va_arg (*ap_savep
, long double);
1164 case PA_STRING
: /* All pointers are the same */
1165 case PA_WSTRING
: /* All pointers are the same */
1166 T (PA_POINTER
, pa_pointer
, void *);
1169 if ((args_type
[cnt
] & PA_FLAG_PTR
) != 0)
1170 args_value
[cnt
].pa_pointer
= va_arg (*ap_savep
, void *);
1171 else if (__glibc_unlikely (__printf_va_arg_table
!= NULL
)
1172 && __printf_va_arg_table
[args_type
[cnt
] - PA_LAST
] != NULL
)
1174 args_value
[cnt
].pa_user
= alloca (args_size
[cnt
]);
1175 (*__printf_va_arg_table
[args_type
[cnt
] - PA_LAST
])
1176 (args_value
[cnt
].pa_user
, ap_savep
);
1179 memset (&args_value
[cnt
], 0, sizeof (args_value
[cnt
]));
1182 /* Error case. Not all parameters appear in N$ format
1183 strings. We have no way to determine their type. */
1184 assert ((mode_flags
& PRINTF_FORTIFY
) != 0);
1185 __libc_fatal ("*** invalid %N$ use detected ***\n");
1188 /* Now walk through all format specifiers and process them. */
1189 for (; (size_t) nspecs_done
< nspecs
&& !Xprintf_buffer_has_failed (buf
);
1197 unsigned long long int longlong
;
1198 unsigned long int word
;
1201 CHAR_T
*string
; /* Pointer to argument string. */
1203 /* Fill variables from values in struct. */
1204 int alt
= specs
[nspecs_done
].info
.alt
;
1205 int space
= specs
[nspecs_done
].info
.space
;
1206 int left
= specs
[nspecs_done
].info
.left
;
1207 int showsign
= specs
[nspecs_done
].info
.showsign
;
1208 int group
= specs
[nspecs_done
].info
.group
;
1209 int is_long_double
__attribute__ ((unused
))
1210 = specs
[nspecs_done
].info
.is_long_double
;
1211 int is_short
= specs
[nspecs_done
].info
.is_short
;
1212 int is_char
= specs
[nspecs_done
].info
.is_char
;
1213 int is_long
= specs
[nspecs_done
].info
.is_long
;
1214 int width
= specs
[nspecs_done
].info
.width
;
1215 int prec
= specs
[nspecs_done
].info
.prec
;
1216 int use_outdigits
= specs
[nspecs_done
].info
.i18n
;
1217 char pad
= specs
[nspecs_done
].info
.pad
;
1218 CHAR_T spec
= specs
[nspecs_done
].info
.spec
;
1220 CHAR_T
*workend
= work_buffer
+ WORK_BUFFER_SIZE
;
1222 /* Fill in last information. */
1223 if (specs
[nspecs_done
].width_arg
!= -1)
1225 /* Extract the field width from an argument. */
1226 specs
[nspecs_done
].info
.width
=
1227 args_value
[specs
[nspecs_done
].width_arg
].pa_int
;
1229 if (specs
[nspecs_done
].info
.width
< 0)
1230 /* If the width value is negative left justification is
1231 selected and the value is taken as being positive. */
1233 specs
[nspecs_done
].info
.width
*= -1;
1234 left
= specs
[nspecs_done
].info
.left
= 1;
1236 width
= specs
[nspecs_done
].info
.width
;
1239 if (specs
[nspecs_done
].prec_arg
!= -1)
1241 /* Extract the precision from an argument. */
1242 specs
[nspecs_done
].info
.prec
=
1243 args_value
[specs
[nspecs_done
].prec_arg
].pa_int
;
1245 if (specs
[nspecs_done
].info
.prec
< 0)
1246 /* If the precision is negative the precision is
1248 specs
[nspecs_done
].info
.prec
= -1;
1250 prec
= specs
[nspecs_done
].info
.prec
;
1253 /* Process format specifiers. */
1256 if (spec
<= UCHAR_MAX
1257 && __printf_function_table
!= NULL
1258 && __printf_function_table
[(size_t) spec
] != NULL
)
1261 = Xprintf (function_invoke
) (buf
,
1262 __printf_function_table
[(size_t) spec
],
1263 &args_value
[specs
[nspecs_done
]
1265 specs
[nspecs_done
].ndata_args
,
1266 &specs
[nspecs_done
].info
);
1267 if (function_done
!= -2)
1269 /* If an error occurred we don't have information
1270 about # of chars. */
1271 if (function_done
< 0)
1273 /* Function has set errno. */
1274 Xprintf_buffer_mark_failed (buf
);
1281 JUMP (spec
, step4_jumps
);
1283 #define process_arg_data args_value[specs[nspecs_done].data_arg]
1284 #define process_arg_int() process_arg_data.pa_int
1285 #define process_arg_long_int() process_arg_data.pa_long_int
1286 #define process_arg_long_long_int() process_arg_data.pa_long_long_int
1287 #define process_arg_pointer() process_arg_data.pa_pointer
1288 #define process_arg_string() process_arg_data.pa_string
1289 #define process_arg_unsigned_int() process_arg_data.pa_u_int
1290 #define process_arg_unsigned_long_int() process_arg_data.pa_u_long_int
1291 #define process_arg_unsigned_long_long_int() process_arg_data.pa_u_long_long_int
1292 #define process_arg_wchar_t() process_arg_data.pa_wchar
1293 #define process_arg_wstring() process_arg_data.pa_wstring
1294 #include "vfprintf-process-arg.c"
1295 #undef process_arg_data
1296 #undef process_arg_int
1297 #undef process_arg_long_int
1298 #undef process_arg_long_long_int
1299 #undef process_arg_pointer
1300 #undef process_arg_string
1301 #undef process_arg_unsigned_int
1302 #undef process_arg_unsigned_long_int
1303 #undef process_arg_unsigned_long_long_int
1304 #undef process_arg_wchar_t
1305 #undef process_arg_wstring
1308 LABEL (form_floathex
):
1311 = (const void *) &args_value
[specs
[nspecs_done
].data_arg
];
1312 if (__glibc_unlikely ((mode_flags
& PRINTF_LDBL_IS_DBL
) != 0))
1314 specs
[nspecs_done
].data_arg_type
= PA_DOUBLE
;
1315 specs
[nspecs_done
].info
.is_long_double
= 0;
1317 SETUP_FLOAT128_INFO (specs
[nspecs_done
].info
);
1319 __printf_fp_spec (buf
, &specs
[nspecs_done
].info
, &ptr
);
1323 LABEL (form_unknown
):
1325 printf_unknown (buf
, &specs
[nspecs_done
].info
);
1329 while (Xprintf_buffer_has_failed (buf
));
1331 /* Write the following constant string. */
1332 Xprintf_buffer_write (buf
,
1333 (const CHAR_T
*) specs
[nspecs_done
].end_of_fmt
,
1334 (specs
[nspecs_done
].next_fmt
1335 - specs
[nspecs_done
].end_of_fmt
));
1338 scratch_buffer_free (&argsbuf
);
1339 scratch_buffer_free (&specsbuf
);
1342 /* Handle an unknown format specifier. This prints out a canonicalized
1343 representation of the format spec itself. */
1345 printf_unknown (struct Xprintf_buffer
*buf
, const struct printf_info
*info
)
1347 CHAR_T work_buffer
[MAX (sizeof (info
->width
), sizeof (info
->prec
)) * 3];
1348 CHAR_T
*const workend
1349 = &work_buffer
[sizeof (work_buffer
) / sizeof (CHAR_T
)];
1352 Xprintf_buffer_putc (buf
, L_('%'));
1355 Xprintf_buffer_putc (buf
, L_('#'));
1357 Xprintf_buffer_putc (buf
, L_('\''));
1359 Xprintf_buffer_putc (buf
, L_('+'));
1360 else if (info
->space
)
1361 Xprintf_buffer_putc (buf
, L_(' '));
1363 Xprintf_buffer_putc (buf
, L_('-'));
1364 if (info
->pad
== L_('0'))
1365 Xprintf_buffer_putc (buf
, L_('0'));
1367 Xprintf_buffer_putc (buf
, L_('I'));
1369 if (info
->width
!= 0)
1371 w
= _itoa_word (info
->width
, workend
, 10, 0);
1373 Xprintf_buffer_putc (buf
, *w
++);
1376 if (info
->prec
!= -1)
1378 Xprintf_buffer_putc (buf
, L_('.'));
1379 w
= _itoa_word (info
->prec
, workend
, 10, 0);
1381 Xprintf_buffer_putc (buf
, *w
++);
1384 if (info
->spec
!= L_('\0'))
1385 Xprintf_buffer_putc (buf
, info
->spec
);
1389 group_number (struct Xprintf_buffer
*buf
,
1390 struct grouping_iterator
*iter
,
1391 CHAR_T
*from
, CHAR_T
*to
, THOUSANDS_SEP_T thousands_sep
,
1395 for (CHAR_T
*cp
= from
; cp
!= to
; ++cp
)
1397 if (__grouping_iterator_next (iter
))
1399 #ifdef COMPILE_WPRINTF
1400 __wprintf_buffer_putc (buf
, thousands_sep
);
1402 __printf_buffer_puts (buf
, thousands_sep
);
1405 Xprintf_buffer_putc (buf
, *cp
);
1409 /* Apply digit translation and grouping. */
1410 for (CHAR_T
*cp
= from
; cp
!= to
; ++cp
)
1412 if (__grouping_iterator_next (iter
))
1414 #ifdef COMPILE_WPRINTF
1415 __wprintf_buffer_putc (buf
, thousands_sep
);
1417 __printf_buffer_puts (buf
, thousands_sep
);
1420 int digit
= *cp
- '0';
1421 #ifdef COMPILE_WPRINTF
1422 __wprintf_buffer_putc
1423 (buf
, _NL_CURRENT_WORD (LC_CTYPE
,
1424 _NL_CTYPE_OUTDIGIT0_WC
+ digit
));
1426 __printf_buffer_puts
1427 (buf
, _NL_CURRENT (LC_CTYPE
, _NL_CTYPE_OUTDIGIT0_MB
+ digit
));
1434 /* The FILE-based function. */
1436 vfprintf (FILE *s
, const CHAR_T
*format
, va_list ap
, unsigned int mode_flags
)
1438 /* Orient the stream. */
1443 /* Sanity check of arguments. */
1444 ARGCHECK (s
, format
);
1447 /* Check for correct orientation. */
1448 if (_IO_vtable_offset (s
) == 0
1449 && _IO_fwide (s
, sizeof (CHAR_T
) == 1 ? -1 : 1)
1450 != (sizeof (CHAR_T
) == 1 ? -1 : 1))
1451 /* The stream is already oriented otherwise. */
1455 if (!_IO_need_lock (s
))
1457 struct Xprintf (buffer_to_file
) wrap
;
1458 Xprintf (buffer_to_file_init
) (&wrap
, s
);
1459 Xprintf_buffer (&wrap
.base
, format
, ap
, mode_flags
);
1460 return Xprintf (buffer_to_file_done
) (&wrap
);
1466 _IO_cleanup_region_start ((void (*) (void *)) &_IO_funlockfile
, s
);
1469 /* Set up the wrapping buffer. */
1470 struct Xprintf (buffer_to_file
) wrap
;
1471 Xprintf (buffer_to_file_init
) (&wrap
, s
);
1473 /* Perform the printing operation on the buffer. */
1474 Xprintf_buffer (&wrap
.base
, format
, ap
, mode_flags
);
1475 done
= Xprintf (buffer_to_file_done
) (&wrap
);
1477 /* Unlock the stream. */
1478 _IO_funlockfile (s
);
1479 _IO_cleanup_region_end (0);