* elf/rtld.c (process_envvars): Fix handling of LD_POINTER_GUARD.
[glibc.git] / stdio-common / vfprintf.c
blobeb11ac28064216f28a13bb4dee5debb84a5270bf
1 /* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <ctype.h>
21 #include <limits.h>
22 #include <printf.h>
23 #include <stdarg.h>
24 #include <stdint.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <errno.h>
28 #include <wchar.h>
29 #include <bits/libc-lock.h>
30 #include <sys/param.h>
31 #include "_itoa.h"
32 #include <locale/localeinfo.h>
33 #include <stdio.h>
35 /* This code is shared between the standard stdio implementation found
36 in GNU C library and the libio implementation originally found in
37 GNU libg++.
39 Beside this it is also shared between the normal and wide character
40 implementation as defined in ISO/IEC 9899:1990/Amendment 1:1995. */
43 #include <libioP.h>
44 #define FILE _IO_FILE
45 #undef va_list
46 #define va_list _IO_va_list
47 #undef BUFSIZ
48 #define BUFSIZ _IO_BUFSIZ
49 #define ARGCHECK(S, Format) \
50 do \
51 { \
52 /* Check file argument for consistence. */ \
53 CHECK_FILE (S, -1); \
54 if (S->_flags & _IO_NO_WRITES) \
55 { \
56 __set_errno (EBADF); \
57 return -1; \
58 } \
59 if (Format == NULL) \
60 { \
61 MAYBE_SET_EINVAL; \
62 return -1; \
63 } \
64 } while (0)
65 #define UNBUFFERED_P(S) ((S)->_IO_file_flags & _IO_UNBUFFERED)
67 #ifndef COMPILE_WPRINTF
68 # define vfprintf _IO_vfprintf_internal
69 # define CHAR_T char
70 # define UCHAR_T unsigned char
71 # define INT_T int
72 # define L_(Str) Str
73 # define ISDIGIT(Ch) ((unsigned int) ((Ch) - '0') < 10)
74 # define STR_LEN(Str) strlen (Str)
76 # define PUT(F, S, N) _IO_sputn ((F), (S), (N))
77 # define PAD(Padchar) \
78 if (width > 0) \
79 done += INTUSE(_IO_padn) (s, (Padchar), width)
80 # define PUTC(C, F) _IO_putc_unlocked (C, F)
81 # define ORIENT if (_IO_vtable_offset (s) == 0 && _IO_fwide (s, -1) != -1)\
82 return -1
83 #else
84 # define vfprintf _IO_vfwprintf
85 # define CHAR_T wchar_t
86 /* This is a hack!!! There should be a type uwchar_t. */
87 # define UCHAR_T unsigned int /* uwchar_t */
88 # define INT_T wint_t
89 # define L_(Str) L##Str
90 # define ISDIGIT(Ch) ((unsigned int) ((Ch) - L'0') < 10)
91 # define STR_LEN(Str) __wcslen (Str)
93 # include "_itowa.h"
95 # define PUT(F, S, N) _IO_sputn ((F), (S), (N))
96 # define PAD(Padchar) \
97 if (width > 0) \
98 done += _IO_wpadn (s, (Padchar), width)
99 # define PUTC(C, F) _IO_putwc_unlocked (C, F)
100 # define ORIENT if (_IO_fwide (s, 1) != 1) return -1
102 # define _itoa(Val, Buf, Base, Case) _itowa (Val, Buf, Base, Case)
103 # define _itoa_word(Val, Buf, Base, Case) _itowa_word (Val, Buf, Base, Case)
104 # undef EOF
105 # define EOF WEOF
106 #endif
108 #include "_i18n_number.h"
110 /* Include the shared code for parsing the format string. */
111 #include "printf-parse.h"
114 #define outchar(Ch) \
115 do \
117 register const INT_T outc = (Ch); \
118 if (PUTC (outc, s) == EOF) \
120 done = -1; \
121 goto all_done; \
123 else \
124 ++done; \
126 while (0)
128 #define outstring(String, Len) \
129 do \
131 if ((size_t) PUT (s, (String), (Len)) != (size_t) (Len)) \
133 done = -1; \
134 goto all_done; \
136 done += (Len); \
138 while (0)
140 /* For handling long_double and longlong we use the same flag. If
141 `long' and `long long' are effectively the same type define it to
142 zero. */
143 #if LONG_MAX == LONG_LONG_MAX
144 # define is_longlong 0
145 #else
146 # define is_longlong is_long_double
147 #endif
149 /* If `long' and `int' is effectively the same type we don't have to
150 handle `long separately. */
151 #if INT_MAX == LONG_MAX
152 # define is_long_num 0
153 #else
154 # define is_long_num is_long
155 #endif
158 /* Global variables. */
159 static const CHAR_T null[] = L_("(null)");
162 /* Helper function to provide temporary buffering for unbuffered streams. */
163 static int buffered_vfprintf (FILE *stream, const CHAR_T *fmt, va_list)
164 __THROW __attribute__ ((noinline)) internal_function;
166 /* Handle unknown format specifier. */
167 static int printf_unknown (FILE *, const struct printf_info *,
168 const void *const *) __THROW;
170 /* Group digits of number string. */
171 #ifdef COMPILE_WPRINTF
172 static CHAR_T *group_number (CHAR_T *, CHAR_T *, const char *, wchar_t)
173 __THROW internal_function;
174 #else
175 static CHAR_T *group_number (CHAR_T *, CHAR_T *, const char *, const char *)
176 __THROW internal_function;
177 #endif
180 /* The function itself. */
182 vfprintf (FILE *s, const CHAR_T *format, va_list ap)
184 /* The character used as thousands separator. */
185 #ifdef COMPILE_WPRINTF
186 wchar_t thousands_sep = L'\0';
187 #else
188 const char *thousands_sep = NULL;
189 #endif
191 /* The string describing the size of groups of digits. */
192 const char *grouping;
194 /* Place to accumulate the result. */
195 int done;
197 /* Current character in format string. */
198 const UCHAR_T *f;
200 /* End of leading constant string. */
201 const UCHAR_T *lead_str_end;
203 /* Points to next format specifier. */
204 const UCHAR_T *end_of_spec;
206 /* Buffer intermediate results. */
207 CHAR_T work_buffer[1000];
208 CHAR_T *workstart = NULL;
209 CHAR_T *workend;
211 /* State for restartable multibyte character handling functions. */
212 #ifndef COMPILE_WPRINTF
213 mbstate_t mbstate;
214 #endif
216 /* We have to save the original argument pointer. */
217 va_list ap_save;
219 /* Count number of specifiers we already processed. */
220 int nspecs_done;
222 /* For the %m format we may need the current `errno' value. */
223 int save_errno = errno;
225 /* 1 if format is in read-only memory, -1 if it is in writable memory,
226 0 if unknown. */
227 int readonly_format = 0;
229 /* This table maps a character into a number representing a
230 class. In each step there is a destination label for each
231 class. */
232 static const int jump_table[] =
234 /* ' ' */ 1, 0, 0, /* '#' */ 4,
235 0, /* '%' */ 14, 0, /* '\''*/ 6,
236 0, 0, /* '*' */ 7, /* '+' */ 2,
237 0, /* '-' */ 3, /* '.' */ 9, 0,
238 /* '0' */ 5, /* '1' */ 8, /* '2' */ 8, /* '3' */ 8,
239 /* '4' */ 8, /* '5' */ 8, /* '6' */ 8, /* '7' */ 8,
240 /* '8' */ 8, /* '9' */ 8, 0, 0,
241 0, 0, 0, 0,
242 0, /* 'A' */ 26, 0, /* 'C' */ 25,
243 0, /* 'E' */ 19, /* F */ 19, /* 'G' */ 19,
244 0, /* 'I' */ 29, 0, 0,
245 /* 'L' */ 12, 0, 0, 0,
246 0, 0, 0, /* 'S' */ 21,
247 0, 0, 0, 0,
248 /* 'X' */ 18, 0, /* 'Z' */ 13, 0,
249 0, 0, 0, 0,
250 0, /* 'a' */ 26, 0, /* 'c' */ 20,
251 /* 'd' */ 15, /* 'e' */ 19, /* 'f' */ 19, /* 'g' */ 19,
252 /* 'h' */ 10, /* 'i' */ 15, /* 'j' */ 28, 0,
253 /* 'l' */ 11, /* 'm' */ 24, /* 'n' */ 23, /* 'o' */ 17,
254 /* 'p' */ 22, /* 'q' */ 12, 0, /* 's' */ 21,
255 /* 't' */ 27, /* 'u' */ 16, 0, 0,
256 /* 'x' */ 18, 0, /* 'z' */ 13
259 #define NOT_IN_JUMP_RANGE(Ch) ((Ch) < L_(' ') || (Ch) > L_('z'))
260 #define CHAR_CLASS(Ch) (jump_table[(INT_T) (Ch) - L_(' ')])
261 #ifdef SHARED
262 /* 'int' is enough and it saves some space on 64 bit systems. */
263 # define JUMP_TABLE_TYPE const int
264 # define JUMP(ChExpr, table) \
265 do \
267 int offset; \
268 void *__unbounded ptr; \
269 spec = (ChExpr); \
270 offset = NOT_IN_JUMP_RANGE (spec) ? REF (form_unknown) \
271 : table[CHAR_CLASS (spec)]; \
272 ptr = &&do_form_unknown + offset; \
273 goto *ptr; \
275 while (0)
276 #else
277 # define JUMP_TABLE_TYPE const void *const
278 # define JUMP(ChExpr, table) \
279 do \
281 const void *__unbounded ptr; \
282 spec = (ChExpr); \
283 ptr = NOT_IN_JUMP_RANGE (spec) ? REF (form_unknown) \
284 : table[CHAR_CLASS (spec)]; \
285 goto *ptr; \
287 while (0)
288 #endif
290 #define STEP0_3_TABLE \
291 /* Step 0: at the beginning. */ \
292 static JUMP_TABLE_TYPE step0_jumps[30] = \
294 REF (form_unknown), \
295 REF (flag_space), /* for ' ' */ \
296 REF (flag_plus), /* for '+' */ \
297 REF (flag_minus), /* for '-' */ \
298 REF (flag_hash), /* for '<hash>' */ \
299 REF (flag_zero), /* for '0' */ \
300 REF (flag_quote), /* for '\'' */ \
301 REF (width_asterics), /* for '*' */ \
302 REF (width), /* for '1'...'9' */ \
303 REF (precision), /* for '.' */ \
304 REF (mod_half), /* for 'h' */ \
305 REF (mod_long), /* for 'l' */ \
306 REF (mod_longlong), /* for 'L', 'q' */ \
307 REF (mod_size_t), /* for 'z', 'Z' */ \
308 REF (form_percent), /* for '%' */ \
309 REF (form_integer), /* for 'd', 'i' */ \
310 REF (form_unsigned), /* for 'u' */ \
311 REF (form_octal), /* for 'o' */ \
312 REF (form_hexa), /* for 'X', 'x' */ \
313 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
314 REF (form_character), /* for 'c' */ \
315 REF (form_string), /* for 's', 'S' */ \
316 REF (form_pointer), /* for 'p' */ \
317 REF (form_number), /* for 'n' */ \
318 REF (form_strerror), /* for 'm' */ \
319 REF (form_wcharacter), /* for 'C' */ \
320 REF (form_floathex), /* for 'A', 'a' */ \
321 REF (mod_ptrdiff_t), /* for 't' */ \
322 REF (mod_intmax_t), /* for 'j' */ \
323 REF (flag_i18n), /* for 'I' */ \
324 }; \
325 /* Step 1: after processing width. */ \
326 static JUMP_TABLE_TYPE step1_jumps[30] = \
328 REF (form_unknown), \
329 REF (form_unknown), /* for ' ' */ \
330 REF (form_unknown), /* for '+' */ \
331 REF (form_unknown), /* for '-' */ \
332 REF (form_unknown), /* for '<hash>' */ \
333 REF (form_unknown), /* for '0' */ \
334 REF (form_unknown), /* for '\'' */ \
335 REF (form_unknown), /* for '*' */ \
336 REF (form_unknown), /* for '1'...'9' */ \
337 REF (precision), /* for '.' */ \
338 REF (mod_half), /* for 'h' */ \
339 REF (mod_long), /* for 'l' */ \
340 REF (mod_longlong), /* for 'L', 'q' */ \
341 REF (mod_size_t), /* for 'z', 'Z' */ \
342 REF (form_percent), /* for '%' */ \
343 REF (form_integer), /* for 'd', 'i' */ \
344 REF (form_unsigned), /* for 'u' */ \
345 REF (form_octal), /* for 'o' */ \
346 REF (form_hexa), /* for 'X', 'x' */ \
347 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
348 REF (form_character), /* for 'c' */ \
349 REF (form_string), /* for 's', 'S' */ \
350 REF (form_pointer), /* for 'p' */ \
351 REF (form_number), /* for 'n' */ \
352 REF (form_strerror), /* for 'm' */ \
353 REF (form_wcharacter), /* for 'C' */ \
354 REF (form_floathex), /* for 'A', 'a' */ \
355 REF (mod_ptrdiff_t), /* for 't' */ \
356 REF (mod_intmax_t), /* for 'j' */ \
357 REF (form_unknown) /* for 'I' */ \
358 }; \
359 /* Step 2: after processing precision. */ \
360 static JUMP_TABLE_TYPE step2_jumps[30] = \
362 REF (form_unknown), \
363 REF (form_unknown), /* for ' ' */ \
364 REF (form_unknown), /* for '+' */ \
365 REF (form_unknown), /* for '-' */ \
366 REF (form_unknown), /* for '<hash>' */ \
367 REF (form_unknown), /* for '0' */ \
368 REF (form_unknown), /* for '\'' */ \
369 REF (form_unknown), /* for '*' */ \
370 REF (form_unknown), /* for '1'...'9' */ \
371 REF (form_unknown), /* for '.' */ \
372 REF (mod_half), /* for 'h' */ \
373 REF (mod_long), /* for 'l' */ \
374 REF (mod_longlong), /* for 'L', 'q' */ \
375 REF (mod_size_t), /* for 'z', 'Z' */ \
376 REF (form_percent), /* for '%' */ \
377 REF (form_integer), /* for 'd', 'i' */ \
378 REF (form_unsigned), /* for 'u' */ \
379 REF (form_octal), /* for 'o' */ \
380 REF (form_hexa), /* for 'X', 'x' */ \
381 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
382 REF (form_character), /* for 'c' */ \
383 REF (form_string), /* for 's', 'S' */ \
384 REF (form_pointer), /* for 'p' */ \
385 REF (form_number), /* for 'n' */ \
386 REF (form_strerror), /* for 'm' */ \
387 REF (form_wcharacter), /* for 'C' */ \
388 REF (form_floathex), /* for 'A', 'a' */ \
389 REF (mod_ptrdiff_t), /* for 't' */ \
390 REF (mod_intmax_t), /* for 'j' */ \
391 REF (form_unknown) /* for 'I' */ \
392 }; \
393 /* Step 3a: after processing first 'h' modifier. */ \
394 static JUMP_TABLE_TYPE step3a_jumps[30] = \
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 (form_unknown), /* for '.' */ \
406 REF (mod_halfhalf), /* for 'h' */ \
407 REF (form_unknown), /* for 'l' */ \
408 REF (form_unknown), /* for 'L', 'q' */ \
409 REF (form_unknown), /* 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_unknown), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
416 REF (form_unknown), /* for 'c' */ \
417 REF (form_unknown), /* for 's', 'S' */ \
418 REF (form_unknown), /* for 'p' */ \
419 REF (form_number), /* for 'n' */ \
420 REF (form_unknown), /* for 'm' */ \
421 REF (form_unknown), /* for 'C' */ \
422 REF (form_unknown), /* for 'A', 'a' */ \
423 REF (form_unknown), /* for 't' */ \
424 REF (form_unknown), /* for 'j' */ \
425 REF (form_unknown) /* for 'I' */ \
426 }; \
427 /* Step 3b: after processing first 'l' modifier. */ \
428 static JUMP_TABLE_TYPE step3b_jumps[30] = \
430 REF (form_unknown), \
431 REF (form_unknown), /* for ' ' */ \
432 REF (form_unknown), /* for '+' */ \
433 REF (form_unknown), /* for '-' */ \
434 REF (form_unknown), /* for '<hash>' */ \
435 REF (form_unknown), /* for '0' */ \
436 REF (form_unknown), /* for '\'' */ \
437 REF (form_unknown), /* for '*' */ \
438 REF (form_unknown), /* for '1'...'9' */ \
439 REF (form_unknown), /* for '.' */ \
440 REF (form_unknown), /* for 'h' */ \
441 REF (mod_longlong), /* for 'l' */ \
442 REF (form_unknown), /* for 'L', 'q' */ \
443 REF (form_unknown), /* for 'z', 'Z' */ \
444 REF (form_percent), /* for '%' */ \
445 REF (form_integer), /* for 'd', 'i' */ \
446 REF (form_unsigned), /* for 'u' */ \
447 REF (form_octal), /* for 'o' */ \
448 REF (form_hexa), /* for 'X', 'x' */ \
449 REF (form_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
450 REF (form_character), /* for 'c' */ \
451 REF (form_string), /* for 's', 'S' */ \
452 REF (form_pointer), /* for 'p' */ \
453 REF (form_number), /* for 'n' */ \
454 REF (form_strerror), /* for 'm' */ \
455 REF (form_wcharacter), /* for 'C' */ \
456 REF (form_floathex), /* for 'A', 'a' */ \
457 REF (form_unknown), /* for 't' */ \
458 REF (form_unknown), /* for 'j' */ \
459 REF (form_unknown) /* for 'I' */ \
462 #define STEP4_TABLE \
463 /* Step 4: processing format specifier. */ \
464 static JUMP_TABLE_TYPE step4_jumps[30] = \
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 (form_unknown), /* 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_float), /* for 'E', 'e', 'F', 'f', 'G', 'g' */ \
486 REF (form_character), /* for 'c' */ \
487 REF (form_string), /* for 's', 'S' */ \
488 REF (form_pointer), /* for 'p' */ \
489 REF (form_number), /* for 'n' */ \
490 REF (form_strerror), /* for 'm' */ \
491 REF (form_wcharacter), /* for 'C' */ \
492 REF (form_floathex), /* for 'A', 'a' */ \
493 REF (form_unknown), /* for 't' */ \
494 REF (form_unknown), /* for 'j' */ \
495 REF (form_unknown) /* for 'I' */ \
499 #define process_arg(fspec) \
500 /* Start real work. We know about all flags and modifiers and \
501 now process the wanted format specifier. */ \
502 LABEL (form_percent): \
503 /* Write a literal "%". */ \
504 outchar (L_('%')); \
505 break; \
507 LABEL (form_integer): \
508 /* Signed decimal integer. */ \
509 base = 10; \
511 if (is_longlong) \
513 long long int signed_number; \
515 if (fspec == NULL) \
516 signed_number = va_arg (ap, long long int); \
517 else \
518 signed_number = args_value[fspec->data_arg].pa_long_long_int; \
520 is_negative = signed_number < 0; \
521 number.longlong = is_negative ? (- signed_number) : signed_number; \
523 goto LABEL (longlong_number); \
525 else \
527 long int signed_number; \
529 if (fspec == NULL) \
531 if (is_long_num) \
532 signed_number = va_arg (ap, long int); \
533 else /* `char' and `short int' will be promoted to `int'. */ \
534 signed_number = va_arg (ap, int); \
536 else \
537 if (is_long_num) \
538 signed_number = args_value[fspec->data_arg].pa_long_int; \
539 else /* `char' and `short int' will be promoted to `int'. */ \
540 signed_number = args_value[fspec->data_arg].pa_int; \
542 is_negative = signed_number < 0; \
543 number.word = is_negative ? (- signed_number) : signed_number; \
545 goto LABEL (number); \
547 /* NOTREACHED */ \
549 LABEL (form_unsigned): \
550 /* Unsigned decimal integer. */ \
551 base = 10; \
552 goto LABEL (unsigned_number); \
553 /* NOTREACHED */ \
555 LABEL (form_octal): \
556 /* Unsigned octal integer. */ \
557 base = 8; \
558 goto LABEL (unsigned_number); \
559 /* NOTREACHED */ \
561 LABEL (form_hexa): \
562 /* Unsigned hexadecimal integer. */ \
563 base = 16; \
565 LABEL (unsigned_number): /* Unsigned number of base BASE. */ \
567 /* ISO specifies the `+' and ` ' flags only for signed \
568 conversions. */ \
569 is_negative = 0; \
570 showsign = 0; \
571 space = 0; \
573 if (is_longlong) \
575 if (fspec == NULL) \
576 number.longlong = va_arg (ap, unsigned long long int); \
577 else \
578 number.longlong = args_value[fspec->data_arg].pa_u_long_long_int; \
580 LABEL (longlong_number): \
581 if (prec < 0) \
582 /* Supply a default precision if none was given. */ \
583 prec = 1; \
584 else \
585 /* We have to take care for the '0' flag. If a precision \
586 is given it must be ignored. */ \
587 pad = L_(' '); \
589 /* If the precision is 0 and the number is 0 nothing has to \
590 be written for the number, except for the 'o' format in \
591 alternate form. */ \
592 if (prec == 0 && number.longlong == 0) \
594 string = workend; \
595 if (base == 8 && alt) \
596 *--string = L_('0'); \
598 else \
600 /* Put the number in WORK. */ \
601 string = _itoa (number.longlong, workend, base, \
602 spec == L_('X')); \
603 if (group && grouping) \
604 string = group_number (string, workend, grouping, \
605 thousands_sep); \
607 if (use_outdigits && base == 10) \
608 string = _i18n_number_rewrite (string, workend); \
610 /* Simplify further test for num != 0. */ \
611 number.word = number.longlong != 0; \
613 else \
615 if (fspec == NULL) \
617 if (is_long_num) \
618 number.word = va_arg (ap, unsigned long int); \
619 else if (is_char) \
620 number.word = (unsigned char) va_arg (ap, unsigned int); \
621 else if (!is_short) \
622 number.word = va_arg (ap, unsigned int); \
623 else \
624 number.word = (unsigned short int) va_arg (ap, unsigned int); \
626 else \
627 if (is_long_num) \
628 number.word = args_value[fspec->data_arg].pa_u_long_int; \
629 else if (is_char) \
630 number.word = (unsigned char) \
631 args_value[fspec->data_arg].pa_u_int; \
632 else if (!is_short) \
633 number.word = args_value[fspec->data_arg].pa_u_int; \
634 else \
635 number.word = (unsigned short int) \
636 args_value[fspec->data_arg].pa_u_int; \
638 LABEL (number): \
639 if (prec < 0) \
640 /* Supply a default precision if none was given. */ \
641 prec = 1; \
642 else \
643 /* We have to take care for the '0' flag. If a precision \
644 is given it must be ignored. */ \
645 pad = L_(' '); \
647 /* If the precision is 0 and the number is 0 nothing has to \
648 be written for the number, except for the 'o' format in \
649 alternate form. */ \
650 if (prec == 0 && number.word == 0) \
652 string = workend; \
653 if (base == 8 && alt) \
654 *--string = L_('0'); \
656 else \
658 /* Put the number in WORK. */ \
659 string = _itoa_word (number.word, workend, base, \
660 spec == L_('X')); \
661 if (group && grouping) \
662 string = group_number (string, workend, grouping, \
663 thousands_sep); \
665 if (use_outdigits && base == 10) \
666 string = _i18n_number_rewrite (string, workend); \
670 if (prec <= workend - string && number.word != 0 && alt && base == 8) \
671 /* Add octal marker. */ \
672 *--string = L_('0'); \
674 prec = MAX (0, prec - (workend - string)); \
676 if (!left) \
678 width -= workend - string + prec; \
680 if (number.word != 0 && alt && base == 16) \
681 /* Account for 0X hex marker. */ \
682 width -= 2; \
684 if (is_negative || showsign || space) \
685 --width; \
687 if (pad == L_(' ')) \
689 PAD (L_(' ')); \
690 width = 0; \
693 if (is_negative) \
694 outchar (L_('-')); \
695 else if (showsign) \
696 outchar (L_('+')); \
697 else if (space) \
698 outchar (L_(' ')); \
700 if (number.word != 0 && alt && base == 16) \
702 outchar (L_('0')); \
703 outchar (spec); \
706 width += prec; \
707 PAD (L_('0')); \
709 outstring (string, workend - string); \
711 break; \
713 else \
715 if (is_negative) \
717 outchar (L_('-')); \
718 --width; \
720 else if (showsign) \
722 outchar (L_('+')); \
723 --width; \
725 else if (space) \
727 outchar (L_(' ')); \
728 --width; \
731 if (number.word != 0 && alt && base == 16) \
733 outchar (L_('0')); \
734 outchar (spec); \
735 width -= 2; \
738 width -= workend - string + prec; \
740 if (prec > 0) \
742 int temp = width; \
743 width = prec; \
744 PAD (L_('0'));; \
745 width = temp; \
748 outstring (string, workend - string); \
750 PAD (L_(' ')); \
751 break; \
754 LABEL (form_float): \
756 /* Floating-point number. This is handled by printf_fp.c. */ \
757 const void *ptr; \
758 int function_done; \
760 if (fspec == NULL) \
762 if (__ldbl_is_dbl) \
763 is_long_double = 0; \
765 struct printf_info info = { .prec = prec, \
766 .width = width, \
767 .spec = spec, \
768 .is_long_double = is_long_double, \
769 .is_short = is_short, \
770 .is_long = is_long, \
771 .alt = alt, \
772 .space = space, \
773 .left = left, \
774 .showsign = showsign, \
775 .group = group, \
776 .pad = pad, \
777 .extra = 0, \
778 .i18n = use_outdigits, \
779 .wide = sizeof (CHAR_T) != 1 }; \
781 if (is_long_double) \
782 the_arg.pa_long_double = va_arg (ap, long double); \
783 else \
784 the_arg.pa_double = va_arg (ap, double); \
785 ptr = (const void *) &the_arg; \
787 function_done = __printf_fp (s, &info, &ptr); \
789 else \
791 ptr = (const void *) &args_value[fspec->data_arg]; \
792 if (__ldbl_is_dbl) \
794 fspec->data_arg_type = PA_DOUBLE; \
795 fspec->info.is_long_double = 0; \
798 function_done = __printf_fp (s, &fspec->info, &ptr); \
801 if (function_done < 0) \
803 /* Error in print handler. */ \
804 done = -1; \
805 goto all_done; \
808 done += function_done; \
810 break; \
812 LABEL (form_floathex): \
814 /* Floating point number printed as hexadecimal number. */ \
815 const void *ptr; \
816 int function_done; \
818 if (fspec == NULL) \
820 if (__ldbl_is_dbl) \
821 is_long_double = 0; \
823 struct printf_info info = { .prec = prec, \
824 .width = width, \
825 .spec = spec, \
826 .is_long_double = is_long_double, \
827 .is_short = is_short, \
828 .is_long = is_long, \
829 .alt = alt, \
830 .space = space, \
831 .left = left, \
832 .showsign = showsign, \
833 .group = group, \
834 .pad = pad, \
835 .extra = 0, \
836 .wide = sizeof (CHAR_T) != 1 }; \
838 if (is_long_double) \
839 the_arg.pa_long_double = va_arg (ap, long double); \
840 else \
841 the_arg.pa_double = va_arg (ap, double); \
842 ptr = (const void *) &the_arg; \
844 function_done = __printf_fphex (s, &info, &ptr); \
846 else \
848 ptr = (const void *) &args_value[fspec->data_arg]; \
849 if (__ldbl_is_dbl) \
850 fspec->info.is_long_double = 0; \
852 function_done = __printf_fphex (s, &fspec->info, &ptr); \
855 if (function_done < 0) \
857 /* Error in print handler. */ \
858 done = -1; \
859 goto all_done; \
862 done += function_done; \
864 break; \
866 LABEL (form_pointer): \
867 /* Generic pointer. */ \
869 const void *ptr; \
870 if (fspec == NULL) \
871 ptr = va_arg (ap, void *); \
872 else \
873 ptr = args_value[fspec->data_arg].pa_pointer; \
874 if (ptr != NULL) \
876 /* If the pointer is not NULL, write it as a %#x spec. */ \
877 base = 16; \
878 number.word = (unsigned long int) ptr; \
879 is_negative = 0; \
880 alt = 1; \
881 group = 0; \
882 spec = L_('x'); \
883 goto LABEL (number); \
885 else \
887 /* Write "(nil)" for a nil pointer. */ \
888 string = (CHAR_T *) L_("(nil)"); \
889 /* Make sure the full string "(nil)" is printed. */ \
890 if (prec < 5) \
891 prec = 5; \
892 is_long = 0; /* This is no wide-char string. */ \
893 goto LABEL (print_string); \
896 /* NOTREACHED */ \
898 LABEL (form_number): \
899 if (s->_flags2 & _IO_FLAGS2_FORTIFY) \
901 if (! readonly_format) \
903 extern int __readonly_area (const void *, size_t) \
904 attribute_hidden; \
905 readonly_format \
906 = __readonly_area (format, ((STR_LEN (format) + 1) \
907 * sizeof (CHAR_T))); \
909 if (readonly_format < 0) \
910 __libc_fatal ("*** %n in writable segment detected ***\n"); \
912 /* Answer the count of characters written. */ \
913 if (fspec == NULL) \
915 if (is_longlong) \
916 *(long long int *) va_arg (ap, void *) = done; \
917 else if (is_long_num) \
918 *(long int *) va_arg (ap, void *) = done; \
919 else if (is_char) \
920 *(char *) va_arg (ap, void *) = done; \
921 else if (!is_short) \
922 *(int *) va_arg (ap, void *) = done; \
923 else \
924 *(short int *) va_arg (ap, void *) = done; \
926 else \
927 if (is_longlong) \
928 *(long long int *) args_value[fspec->data_arg].pa_pointer = done; \
929 else if (is_long_num) \
930 *(long int *) args_value[fspec->data_arg].pa_pointer = done; \
931 else if (is_char) \
932 *(char *) args_value[fspec->data_arg].pa_pointer = done; \
933 else if (!is_short) \
934 *(int *) args_value[fspec->data_arg].pa_pointer = done; \
935 else \
936 *(short int *) args_value[fspec->data_arg].pa_pointer = done; \
937 break; \
939 LABEL (form_strerror): \
940 /* Print description of error ERRNO. */ \
941 string = \
942 (CHAR_T *) __strerror_r (save_errno, (char *) work_buffer, \
943 sizeof work_buffer); \
944 is_long = 0; /* This is no wide-char string. */ \
945 goto LABEL (print_string)
947 #ifdef COMPILE_WPRINTF
948 # define process_string_arg(fspec) \
949 LABEL (form_character): \
950 /* Character. */ \
951 if (is_long) \
952 goto LABEL (form_wcharacter); \
953 --width; /* Account for the character itself. */ \
954 if (!left) \
955 PAD (L' '); \
956 if (fspec == NULL) \
957 outchar (__btowc ((unsigned char) va_arg (ap, int))); /* Promoted. */ \
958 else \
959 outchar (__btowc ((unsigned char) \
960 args_value[fspec->data_arg].pa_int)); \
961 if (left) \
962 PAD (L' '); \
963 break; \
965 LABEL (form_wcharacter): \
967 /* Wide character. */ \
968 --width; \
969 if (!left) \
970 PAD (L' '); \
971 if (fspec == NULL) \
972 outchar (va_arg (ap, wchar_t)); \
973 else \
974 outchar (args_value[fspec->data_arg].pa_wchar); \
975 if (left) \
976 PAD (L' '); \
978 break; \
980 LABEL (form_string): \
982 size_t len; \
983 int string_malloced; \
985 /* The string argument could in fact be `char *' or `wchar_t *'. \
986 But this should not make a difference here. */ \
987 if (fspec == NULL) \
988 string = (CHAR_T *) va_arg (ap, const wchar_t *); \
989 else \
990 string = (CHAR_T *) args_value[fspec->data_arg].pa_wstring; \
992 /* Entry point for printing other strings. */ \
993 LABEL (print_string): \
995 string_malloced = 0; \
996 if (string == NULL) \
998 /* Write "(null)" if there's space. */ \
999 if (prec == -1 \
1000 || prec >= (int) (sizeof (null) / sizeof (null[0])) - 1) \
1002 string = (CHAR_T *) null; \
1003 len = (sizeof (null) / sizeof (null[0])) - 1; \
1005 else \
1007 string = (CHAR_T *) L""; \
1008 len = 0; \
1011 else if (!is_long && spec != L_('S')) \
1013 /* This is complicated. We have to transform the multibyte \
1014 string into a wide character string. */ \
1015 const char *mbs = (const char *) string; \
1016 mbstate_t mbstate; \
1018 len = prec != -1 ? (size_t) prec : strlen (mbs); \
1020 /* Allocate dynamically an array which definitely is long \
1021 enough for the wide character version. */ \
1022 if (__libc_use_alloca (len * sizeof (wchar_t))) \
1023 string = (CHAR_T *) alloca (len * sizeof (wchar_t)); \
1024 else if ((string = (CHAR_T *) malloc (len * sizeof (wchar_t))) \
1025 == NULL) \
1027 done = -1; \
1028 goto all_done; \
1030 else \
1031 string_malloced = 1; \
1033 memset (&mbstate, '\0', sizeof (mbstate_t)); \
1034 len = __mbsrtowcs (string, &mbs, len, &mbstate); \
1035 if (len == (size_t) -1) \
1037 /* Illegal multibyte character. */ \
1038 done = -1; \
1039 goto all_done; \
1042 else \
1044 if (prec != -1) \
1045 /* Search for the end of the string, but don't search past \
1046 the length specified by the precision. */ \
1047 len = __wcsnlen (string, prec); \
1048 else \
1049 len = __wcslen (string); \
1052 if ((width -= len) < 0) \
1054 outstring (string, len); \
1055 break; \
1058 if (!left) \
1059 PAD (L' '); \
1060 outstring (string, len); \
1061 if (left) \
1062 PAD (L' '); \
1063 if (__builtin_expect (string_malloced, 0)) \
1064 free (string); \
1066 break;
1067 #else
1068 # define process_string_arg(fspec) \
1069 LABEL (form_character): \
1070 /* Character. */ \
1071 if (is_long) \
1072 goto LABEL (form_wcharacter); \
1073 --width; /* Account for the character itself. */ \
1074 if (!left) \
1075 PAD (' '); \
1076 if (fspec == NULL) \
1077 outchar ((unsigned char) va_arg (ap, int)); /* Promoted. */ \
1078 else \
1079 outchar ((unsigned char) args_value[fspec->data_arg].pa_int); \
1080 if (left) \
1081 PAD (' '); \
1082 break; \
1084 LABEL (form_wcharacter): \
1086 /* Wide character. */ \
1087 char buf[MB_CUR_MAX]; \
1088 mbstate_t mbstate; \
1089 size_t len; \
1091 memset (&mbstate, '\0', sizeof (mbstate_t)); \
1092 len = __wcrtomb (buf, (fspec == NULL ? va_arg (ap, wchar_t) \
1093 : args_value[fspec->data_arg].pa_wchar), \
1094 &mbstate); \
1095 if (len == (size_t) -1) \
1097 /* Something went wron gduring the conversion. Bail out. */ \
1098 done = -1; \
1099 goto all_done; \
1101 width -= len; \
1102 if (!left) \
1103 PAD (' '); \
1104 outstring (buf, len); \
1105 if (left) \
1106 PAD (' '); \
1108 break; \
1110 LABEL (form_string): \
1112 size_t len; \
1113 int string_malloced; \
1115 /* The string argument could in fact be `char *' or `wchar_t *'. \
1116 But this should not make a difference here. */ \
1117 if (fspec == NULL) \
1118 string = (char *) va_arg (ap, const char *); \
1119 else \
1120 string = (char *) args_value[fspec->data_arg].pa_string; \
1122 /* Entry point for printing other strings. */ \
1123 LABEL (print_string): \
1125 string_malloced = 0; \
1126 if (string == NULL) \
1128 /* Write "(null)" if there's space. */ \
1129 if (prec == -1 || prec >= (int) sizeof (null) - 1) \
1131 string = (char *) null; \
1132 len = sizeof (null) - 1; \
1134 else \
1136 string = (char *) ""; \
1137 len = 0; \
1140 else if (!is_long && spec != L_('S')) \
1142 if (prec != -1) \
1144 /* Search for the end of the string, but don't search past \
1145 the length (in bytes) specified by the precision. Also \
1146 don't use incomplete characters. */ \
1147 if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MB_CUR_MAX) == 1) \
1148 len = __strnlen (string, prec); \
1149 else \
1151 /* In case we have a multibyte character set the \
1152 situation is more compilcated. We must not copy \
1153 bytes at the end which form an incomplete character. */\
1154 wchar_t ignore[prec]; \
1155 const char *str2 = string; \
1156 mbstate_t ps; \
1158 memset (&ps, '\0', sizeof (ps)); \
1159 if (__mbsnrtowcs (ignore, &str2, prec, prec, &ps) \
1160 == (size_t) -1) \
1162 done = -1; \
1163 goto all_done; \
1165 if (str2 == NULL) \
1166 len = strlen (string); \
1167 else \
1168 len = str2 - string - (ps.__count & 7); \
1171 else \
1172 len = strlen (string); \
1174 else \
1176 const wchar_t *s2 = (const wchar_t *) string; \
1177 mbstate_t mbstate; \
1179 memset (&mbstate, '\0', sizeof (mbstate_t)); \
1181 if (prec >= 0) \
1183 /* The string `s2' might not be NUL terminated. */ \
1184 if (__libc_use_alloca (prec)) \
1185 string = (char *) alloca (prec); \
1186 else if ((string = (char *) malloc (prec)) == NULL) \
1188 done = -1; \
1189 goto all_done; \
1191 else \
1192 string_malloced = 1; \
1193 len = __wcsrtombs (string, &s2, prec, &mbstate); \
1195 else \
1197 len = __wcsrtombs (NULL, &s2, 0, &mbstate); \
1198 if (len != (size_t) -1) \
1200 assert (__mbsinit (&mbstate)); \
1201 s2 = (const wchar_t *) string; \
1202 if (__libc_use_alloca (len + 1)) \
1203 string = (char *) alloca (len + 1); \
1204 else if ((string = (char *) malloc (len + 1)) == NULL) \
1206 done = -1; \
1207 goto all_done; \
1209 else \
1210 string_malloced = 1; \
1211 (void) __wcsrtombs (string, &s2, len + 1, &mbstate); \
1215 if (len == (size_t) -1) \
1217 /* Illegal wide-character string. */ \
1218 done = -1; \
1219 goto all_done; \
1223 if ((width -= len) < 0) \
1225 outstring (string, len); \
1226 break; \
1229 if (!left) \
1230 PAD (' '); \
1231 outstring (string, len); \
1232 if (left) \
1233 PAD (' '); \
1234 if (__builtin_expect (string_malloced, 0)) \
1235 free (string); \
1237 break;
1238 #endif
1240 /* Orient the stream. */
1241 #ifdef ORIENT
1242 ORIENT;
1243 #endif
1245 /* Sanity check of arguments. */
1246 ARGCHECK (s, format);
1248 #ifdef ORIENT
1249 /* Check for correct orientation. */
1250 if (_IO_vtable_offset (s) == 0 &&
1251 _IO_fwide (s, sizeof (CHAR_T) == 1 ? -1 : 1)
1252 != (sizeof (CHAR_T) == 1 ? -1 : 1))
1253 /* The stream is already oriented otherwise. */
1254 return EOF;
1255 #endif
1257 if (UNBUFFERED_P (s))
1258 /* Use a helper function which will allocate a local temporary buffer
1259 for the stream and then call us again. */
1260 return buffered_vfprintf (s, format, ap);
1262 /* Initialize local variables. */
1263 done = 0;
1264 grouping = (const char *) -1;
1265 #ifdef __va_copy
1266 /* This macro will be available soon in gcc's <stdarg.h>. We need it
1267 since on some systems `va_list' is not an integral type. */
1268 __va_copy (ap_save, ap);
1269 #else
1270 ap_save = ap;
1271 #endif
1272 nspecs_done = 0;
1274 #ifdef COMPILE_WPRINTF
1275 /* Find the first format specifier. */
1276 f = lead_str_end = __find_specwc ((const UCHAR_T *) format);
1277 #else
1278 /* Put state for processing format string in initial state. */
1279 memset (&mbstate, '\0', sizeof (mbstate_t));
1281 /* Find the first format specifier. */
1282 f = lead_str_end = __find_specmb (format, &mbstate);
1283 #endif
1285 /* Lock stream. */
1286 _IO_cleanup_region_start ((void (*) (void *)) &_IO_funlockfile, s);
1287 _IO_flockfile (s);
1289 /* Write the literal text before the first format. */
1290 outstring ((const UCHAR_T *) format,
1291 lead_str_end - (const UCHAR_T *) format);
1293 /* If we only have to print a simple string, return now. */
1294 if (*f == L_('\0'))
1295 goto all_done;
1297 /* Process whole format string. */
1300 #ifdef SHARED
1301 # define REF(Name) &&do_##Name - &&do_form_unknown
1302 #else
1303 # define REF(Name) &&do_##Name
1304 #endif
1305 #define LABEL(Name) do_##Name
1306 STEP0_3_TABLE;
1307 STEP4_TABLE;
1309 union printf_arg *args_value; /* This is not used here but ... */
1310 int is_negative; /* Flag for negative number. */
1311 union
1313 unsigned long long int longlong;
1314 unsigned long int word;
1315 } number;
1316 int base;
1317 union printf_arg the_arg;
1318 CHAR_T *string; /* Pointer to argument string. */
1319 int alt = 0; /* Alternate format. */
1320 int space = 0; /* Use space prefix if no sign is needed. */
1321 int left = 0; /* Left-justify output. */
1322 int showsign = 0; /* Always begin with plus or minus sign. */
1323 int group = 0; /* Print numbers according grouping rules. */
1324 int is_long_double = 0; /* Argument is long double/ long long int. */
1325 int is_short = 0; /* Argument is short int. */
1326 int is_long = 0; /* Argument is long int. */
1327 int is_char = 0; /* Argument is promoted (unsigned) char. */
1328 int width = 0; /* Width of output; 0 means none specified. */
1329 int prec = -1; /* Precision of output; -1 means none specified. */
1330 /* This flag is set by the 'I' modifier and selects the use of the
1331 `outdigits' as determined by the current locale. */
1332 int use_outdigits = 0;
1333 UCHAR_T pad = L_(' ');/* Padding character. */
1334 CHAR_T spec;
1336 workstart = NULL;
1337 workend = &work_buffer[sizeof (work_buffer) / sizeof (CHAR_T)];
1339 /* Get current character in format string. */
1340 JUMP (*++f, step0_jumps);
1342 /* ' ' flag. */
1343 LABEL (flag_space):
1344 space = 1;
1345 JUMP (*++f, step0_jumps);
1347 /* '+' flag. */
1348 LABEL (flag_plus):
1349 showsign = 1;
1350 JUMP (*++f, step0_jumps);
1352 /* The '-' flag. */
1353 LABEL (flag_minus):
1354 left = 1;
1355 pad = L_(' ');
1356 JUMP (*++f, step0_jumps);
1358 /* The '#' flag. */
1359 LABEL (flag_hash):
1360 alt = 1;
1361 JUMP (*++f, step0_jumps);
1363 /* The '0' flag. */
1364 LABEL (flag_zero):
1365 if (!left)
1366 pad = L_('0');
1367 JUMP (*++f, step0_jumps);
1369 /* The '\'' flag. */
1370 LABEL (flag_quote):
1371 group = 1;
1373 if (grouping == (const char *) -1)
1375 #ifdef COMPILE_WPRINTF
1376 thousands_sep = _NL_CURRENT_WORD (LC_NUMERIC,
1377 _NL_NUMERIC_THOUSANDS_SEP_WC);
1378 #else
1379 thousands_sep = _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
1380 #endif
1382 grouping = _NL_CURRENT (LC_NUMERIC, GROUPING);
1383 if (*grouping == '\0' || *grouping == CHAR_MAX
1384 #ifdef COMPILE_WPRINTF
1385 || thousands_sep == L'\0'
1386 #else
1387 || *thousands_sep == '\0'
1388 #endif
1390 grouping = NULL;
1392 JUMP (*++f, step0_jumps);
1394 LABEL (flag_i18n):
1395 use_outdigits = 1;
1396 JUMP (*++f, step0_jumps);
1398 /* Get width from argument. */
1399 LABEL (width_asterics):
1401 const UCHAR_T *tmp; /* Temporary value. */
1403 tmp = ++f;
1404 if (ISDIGIT (*tmp) && read_int (&tmp) && *tmp == L_('$'))
1405 /* The width comes from a positional parameter. */
1406 goto do_positional;
1408 width = va_arg (ap, int);
1410 /* Negative width means left justified. */
1411 if (width < 0)
1413 width = -width;
1414 pad = L_(' ');
1415 left = 1;
1418 if (width + 32 >= (int) (sizeof (work_buffer)
1419 / sizeof (work_buffer[0])))
1421 /* We have to use a special buffer. The "32" is just a safe
1422 bet for all the output which is not counted in the width. */
1423 if (__libc_use_alloca ((width + 32) * sizeof (CHAR_T)))
1424 workend = ((CHAR_T *) alloca ((width + 32) * sizeof (CHAR_T))
1425 + (width + 32));
1426 else
1428 workstart = (CHAR_T *) malloc ((width + 32) * sizeof (CHAR_T));
1429 if (workstart == NULL)
1431 done = -1;
1432 goto all_done;
1434 workend = workstart + (width + 32);
1438 JUMP (*f, step1_jumps);
1440 /* Given width in format string. */
1441 LABEL (width):
1442 width = read_int (&f);
1444 if (width + 32 >= (int) (sizeof (work_buffer) / sizeof (work_buffer[0])))
1446 /* We have to use a special buffer. The "32" is just a safe
1447 bet for all the output which is not counted in the width. */
1448 if (__libc_use_alloca ((width + 32) * sizeof (CHAR_T)))
1449 workend = ((CHAR_T *) alloca ((width + 32) * sizeof (CHAR_T))
1450 + (width + 32));
1451 else
1453 workstart = (CHAR_T *) malloc ((width + 32) * sizeof (CHAR_T));
1454 if (workstart == NULL)
1456 done = -1;
1457 goto all_done;
1459 workend = workstart + (width + 32);
1462 if (*f == L_('$'))
1463 /* Oh, oh. The argument comes from a positional parameter. */
1464 goto do_positional;
1465 JUMP (*f, step1_jumps);
1467 LABEL (precision):
1468 ++f;
1469 if (*f == L_('*'))
1471 const UCHAR_T *tmp; /* Temporary value. */
1473 tmp = ++f;
1474 if (ISDIGIT (*tmp) && read_int (&tmp) > 0 && *tmp == L_('$'))
1475 /* The precision comes from a positional parameter. */
1476 goto do_positional;
1478 prec = va_arg (ap, int);
1480 /* If the precision is negative the precision is omitted. */
1481 if (prec < 0)
1482 prec = -1;
1484 else if (ISDIGIT (*f))
1485 prec = read_int (&f);
1486 else
1487 prec = 0;
1488 if (prec > width
1489 && prec + 32 > (int)(sizeof (work_buffer) / sizeof (work_buffer[0])))
1491 if (__libc_use_alloca ((prec + 32) * sizeof (CHAR_T)))
1492 workend = ((CHAR_T *) alloca ((prec + 32) * sizeof (CHAR_T)))
1493 + (prec + 32);
1494 else
1496 workstart = (CHAR_T *) malloc ((prec + 32) * sizeof (CHAR_T));
1497 if (workstart == NULL)
1499 done = -1;
1500 goto all_done;
1502 workend = workstart + (prec + 32);
1505 JUMP (*f, step2_jumps);
1507 /* Process 'h' modifier. There might another 'h' following. */
1508 LABEL (mod_half):
1509 is_short = 1;
1510 JUMP (*++f, step3a_jumps);
1512 /* Process 'hh' modifier. */
1513 LABEL (mod_halfhalf):
1514 is_short = 0;
1515 is_char = 1;
1516 JUMP (*++f, step4_jumps);
1518 /* Process 'l' modifier. There might another 'l' following. */
1519 LABEL (mod_long):
1520 is_long = 1;
1521 JUMP (*++f, step3b_jumps);
1523 /* Process 'L', 'q', or 'll' modifier. No other modifier is
1524 allowed to follow. */
1525 LABEL (mod_longlong):
1526 is_long_double = 1;
1527 is_long = 1;
1528 JUMP (*++f, step4_jumps);
1530 LABEL (mod_size_t):
1531 is_long_double = sizeof (size_t) > sizeof (unsigned long int);
1532 is_long = sizeof (size_t) > sizeof (unsigned int);
1533 JUMP (*++f, step4_jumps);
1535 LABEL (mod_ptrdiff_t):
1536 is_long_double = sizeof (ptrdiff_t) > sizeof (unsigned long int);
1537 is_long = sizeof (ptrdiff_t) > sizeof (unsigned int);
1538 JUMP (*++f, step4_jumps);
1540 LABEL (mod_intmax_t):
1541 is_long_double = sizeof (intmax_t) > sizeof (unsigned long int);
1542 is_long = sizeof (intmax_t) > sizeof (unsigned int);
1543 JUMP (*++f, step4_jumps);
1545 /* Process current format. */
1546 while (1)
1548 process_arg (((struct printf_spec *) NULL));
1549 process_string_arg (((struct printf_spec *) NULL));
1551 LABEL (form_unknown):
1552 if (spec == L_('\0'))
1554 /* The format string ended before the specifier is complete. */
1555 done = -1;
1556 goto all_done;
1559 /* If we are in the fast loop force entering the complicated
1560 one. */
1561 goto do_positional;
1564 /* The format is correctly handled. */
1565 ++nspecs_done;
1567 if (__builtin_expect (workstart != NULL, 0))
1568 free (workstart);
1569 workstart = NULL;
1571 /* Look for next format specifier. */
1572 #ifdef COMPILE_WPRINTF
1573 f = __find_specwc ((end_of_spec = ++f));
1574 #else
1575 f = __find_specmb ((end_of_spec = ++f), &mbstate);
1576 #endif
1578 /* Write the following constant string. */
1579 outstring (end_of_spec, f - end_of_spec);
1581 while (*f != L_('\0'));
1583 /* Unlock stream and return. */
1584 goto all_done;
1586 /* Here starts the more complex loop to handle positional parameters. */
1587 do_positional:
1589 /* Array with information about the needed arguments. This has to
1590 be dynamically extensible. */
1591 size_t nspecs = 0;
1592 size_t nspecs_max = 32; /* A more or less arbitrary start value. */
1593 struct printf_spec *specs
1594 = alloca (nspecs_max * sizeof (struct printf_spec));
1596 /* The number of arguments the format string requests. This will
1597 determine the size of the array needed to store the argument
1598 attributes. */
1599 size_t nargs = 0;
1600 int *args_type;
1601 union printf_arg *args_value = NULL;
1603 /* Positional parameters refer to arguments directly. This could
1604 also determine the maximum number of arguments. Track the
1605 maximum number. */
1606 size_t max_ref_arg = 0;
1608 /* Just a counter. */
1609 size_t cnt;
1612 if (grouping == (const char *) -1)
1614 #ifdef COMPILE_WPRINTF
1615 thousands_sep = _NL_CURRENT_WORD (LC_NUMERIC,
1616 _NL_NUMERIC_THOUSANDS_SEP_WC);
1617 #else
1618 thousands_sep = _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
1619 #endif
1621 grouping = _NL_CURRENT (LC_NUMERIC, GROUPING);
1622 if (*grouping == '\0' || *grouping == CHAR_MAX)
1623 grouping = NULL;
1626 for (f = lead_str_end; *f != L_('\0'); f = specs[nspecs++].next_fmt)
1628 if (nspecs >= nspecs_max)
1630 /* Extend the array of format specifiers. */
1631 struct printf_spec *old = specs;
1633 nspecs_max *= 2;
1634 specs = alloca (nspecs_max * sizeof (struct printf_spec));
1636 if (specs == &old[nspecs])
1637 /* Stack grows up, OLD was the last thing allocated;
1638 extend it. */
1639 nspecs_max += nspecs_max / 2;
1640 else
1642 /* Copy the old array's elements to the new space. */
1643 memcpy (specs, old, nspecs * sizeof (struct printf_spec));
1644 if (old == &specs[nspecs])
1645 /* Stack grows down, OLD was just below the new
1646 SPECS. We can use that space when the new space
1647 runs out. */
1648 nspecs_max += nspecs_max / 2;
1652 /* Parse the format specifier. */
1653 #ifdef COMPILE_WPRINTF
1654 nargs += __parse_one_specwc (f, nargs, &specs[nspecs], &max_ref_arg);
1655 #else
1656 nargs += __parse_one_specmb (f, nargs, &specs[nspecs], &max_ref_arg,
1657 &mbstate);
1658 #endif
1661 /* Determine the number of arguments the format string consumes. */
1662 nargs = MAX (nargs, max_ref_arg);
1664 /* Allocate memory for the argument descriptions. */
1665 args_type = alloca (nargs * sizeof (int));
1666 memset (args_type, s->_flags2 & _IO_FLAGS2_FORTIFY ? '\xff' : '\0',
1667 nargs * sizeof (int));
1668 args_value = alloca (nargs * sizeof (union printf_arg));
1670 /* XXX Could do sanity check here: If any element in ARGS_TYPE is
1671 still zero after this loop, format is invalid. For now we
1672 simply use 0 as the value. */
1674 /* Fill in the types of all the arguments. */
1675 for (cnt = 0; cnt < nspecs; ++cnt)
1677 /* If the width is determined by an argument this is an int. */
1678 if (specs[cnt].width_arg != -1)
1679 args_type[specs[cnt].width_arg] = PA_INT;
1681 /* If the precision is determined by an argument this is an int. */
1682 if (specs[cnt].prec_arg != -1)
1683 args_type[specs[cnt].prec_arg] = PA_INT;
1685 switch (specs[cnt].ndata_args)
1687 case 0: /* No arguments. */
1688 break;
1689 case 1: /* One argument; we already have the type. */
1690 args_type[specs[cnt].data_arg] = specs[cnt].data_arg_type;
1691 break;
1692 default:
1693 /* We have more than one argument for this format spec.
1694 We must call the arginfo function again to determine
1695 all the types. */
1696 (void) (*__printf_arginfo_table[specs[cnt].info.spec])
1697 (&specs[cnt].info,
1698 specs[cnt].ndata_args, &args_type[specs[cnt].data_arg]);
1699 break;
1703 /* Now we know all the types and the order. Fill in the argument
1704 values. */
1705 for (cnt = 0; cnt < nargs; ++cnt)
1706 switch (args_type[cnt])
1708 #define T(tag, mem, type) \
1709 case tag: \
1710 args_value[cnt].mem = va_arg (ap_save, type); \
1711 break
1713 T (PA_CHAR, pa_int, int); /* Promoted. */
1714 T (PA_WCHAR, pa_wchar, wint_t);
1715 T (PA_INT|PA_FLAG_SHORT, pa_int, int); /* Promoted. */
1716 T (PA_INT, pa_int, int);
1717 T (PA_INT|PA_FLAG_LONG, pa_long_int, long int);
1718 T (PA_INT|PA_FLAG_LONG_LONG, pa_long_long_int, long long int);
1719 T (PA_FLOAT, pa_double, double); /* Promoted. */
1720 T (PA_DOUBLE, pa_double, double);
1721 case PA_DOUBLE|PA_FLAG_LONG_DOUBLE:
1722 if (__ldbl_is_dbl)
1724 args_value[cnt].pa_double = va_arg (ap_save, double);
1725 args_type[cnt] &= ~PA_FLAG_LONG_DOUBLE;
1727 else
1728 args_value[cnt].pa_long_double = va_arg (ap_save, long double);
1729 break;
1730 T (PA_STRING, pa_string, const char *);
1731 T (PA_WSTRING, pa_wstring, const wchar_t *);
1732 T (PA_POINTER, pa_pointer, void *);
1733 #undef T
1734 default:
1735 if ((args_type[cnt] & PA_FLAG_PTR) != 0)
1736 args_value[cnt].pa_pointer = va_arg (ap_save, void *);
1737 else
1738 args_value[cnt].pa_long_double = 0.0;
1739 break;
1740 case -1:
1741 /* Error case. Not all parameters appear in N$ format
1742 strings. We have no way to determine their type. */
1743 assert (s->_flags2 & _IO_FLAGS2_FORTIFY);
1744 __libc_fatal ("*** invalid %N$ use detected ***\n");
1747 /* Now walk through all format specifiers and process them. */
1748 for (; (size_t) nspecs_done < nspecs; ++nspecs_done)
1750 #undef REF
1751 #ifdef SHARED
1752 # define REF(Name) &&do2_##Name - &&do_form_unknown
1753 #else
1754 # define REF(Name) &&do2_##Name
1755 #endif
1756 #undef LABEL
1757 #define LABEL(Name) do2_##Name
1758 STEP4_TABLE;
1760 int is_negative;
1761 union
1763 unsigned long long int longlong;
1764 unsigned long int word;
1765 } number;
1766 int base;
1767 union printf_arg the_arg;
1768 CHAR_T *string; /* Pointer to argument string. */
1770 /* Fill variables from values in struct. */
1771 int alt = specs[nspecs_done].info.alt;
1772 int space = specs[nspecs_done].info.space;
1773 int left = specs[nspecs_done].info.left;
1774 int showsign = specs[nspecs_done].info.showsign;
1775 int group = specs[nspecs_done].info.group;
1776 int is_long_double = specs[nspecs_done].info.is_long_double;
1777 int is_short = specs[nspecs_done].info.is_short;
1778 int is_char = specs[nspecs_done].info.is_char;
1779 int is_long = specs[nspecs_done].info.is_long;
1780 int width = specs[nspecs_done].info.width;
1781 int prec = specs[nspecs_done].info.prec;
1782 int use_outdigits = specs[nspecs_done].info.i18n;
1783 char pad = specs[nspecs_done].info.pad;
1784 CHAR_T spec = specs[nspecs_done].info.spec;
1785 CHAR_T *workstart = NULL;
1787 /* Fill in last information. */
1788 if (specs[nspecs_done].width_arg != -1)
1790 /* Extract the field width from an argument. */
1791 specs[nspecs_done].info.width =
1792 args_value[specs[nspecs_done].width_arg].pa_int;
1794 if (specs[nspecs_done].info.width < 0)
1795 /* If the width value is negative left justification is
1796 selected and the value is taken as being positive. */
1798 specs[nspecs_done].info.width *= -1;
1799 left = specs[nspecs_done].info.left = 1;
1801 width = specs[nspecs_done].info.width;
1804 if (specs[nspecs_done].prec_arg != -1)
1806 /* Extract the precision from an argument. */
1807 specs[nspecs_done].info.prec =
1808 args_value[specs[nspecs_done].prec_arg].pa_int;
1810 if (specs[nspecs_done].info.prec < 0)
1811 /* If the precision is negative the precision is
1812 omitted. */
1813 specs[nspecs_done].info.prec = -1;
1815 prec = specs[nspecs_done].info.prec;
1818 /* Maybe the buffer is too small. */
1819 if (MAX (prec, width) + 32 > (int) (sizeof (work_buffer)
1820 / sizeof (CHAR_T)))
1822 if (__libc_use_alloca ((MAX (prec, width) + 32)
1823 * sizeof (CHAR_T)))
1824 workend = ((CHAR_T *) alloca ((MAX (prec, width) + 32)
1825 * sizeof (CHAR_T))
1826 + (MAX (prec, width) + 32));
1827 else
1829 workstart = (CHAR_T *) malloc ((MAX (prec, width) + 32)
1830 * sizeof (CHAR_T));
1831 workend = workstart + (MAX (prec, width) + 32);
1835 /* Process format specifiers. */
1836 while (1)
1838 JUMP (spec, step4_jumps);
1840 process_arg ((&specs[nspecs_done]));
1841 process_string_arg ((&specs[nspecs_done]));
1843 LABEL (form_unknown):
1845 extern printf_function **__printf_function_table;
1846 int function_done;
1847 printf_function *function;
1848 unsigned int i;
1849 const void **ptr;
1851 function =
1852 (__printf_function_table == NULL ? NULL :
1853 __printf_function_table[specs[nspecs_done].info.spec]);
1855 if (function == NULL)
1856 function = &printf_unknown;
1858 ptr = alloca (specs[nspecs_done].ndata_args
1859 * sizeof (const void *));
1861 /* Fill in an array of pointers to the argument values. */
1862 for (i = 0; i < specs[nspecs_done].ndata_args; ++i)
1863 ptr[i] = &args_value[specs[nspecs_done].data_arg + i];
1865 /* Call the function. */
1866 function_done = (*function) (s, &specs[nspecs_done].info, ptr);
1868 /* If an error occurred we don't have information about #
1869 of chars. */
1870 if (function_done < 0)
1872 done = -1;
1873 goto all_done;
1876 done += function_done;
1878 break;
1881 if (__builtin_expect (workstart != NULL, 0))
1882 free (workstart);
1883 workstart = NULL;
1885 /* Write the following constant string. */
1886 outstring (specs[nspecs_done].end_of_fmt,
1887 specs[nspecs_done].next_fmt
1888 - specs[nspecs_done].end_of_fmt);
1892 all_done:
1893 if (__builtin_expect (workstart != NULL, 0))
1894 free (workstart);
1895 /* Unlock the stream. */
1896 _IO_funlockfile (s);
1897 _IO_cleanup_region_end (0);
1899 return done;
1902 /* Handle an unknown format specifier. This prints out a canonicalized
1903 representation of the format spec itself. */
1904 static int
1905 printf_unknown (FILE *s, const struct printf_info *info,
1906 const void *const *args)
1909 int done = 0;
1910 CHAR_T work_buffer[MAX (info->width, info->spec) + 32];
1911 CHAR_T *const workend
1912 = &work_buffer[sizeof (work_buffer) / sizeof (CHAR_T)];
1913 register CHAR_T *w;
1915 outchar (L_('%'));
1917 if (info->alt)
1918 outchar (L_('#'));
1919 if (info->group)
1920 outchar (L_('\''));
1921 if (info->showsign)
1922 outchar (L_('+'));
1923 else if (info->space)
1924 outchar (L_(' '));
1925 if (info->left)
1926 outchar (L_('-'));
1927 if (info->pad == L_('0'))
1928 outchar (L_('0'));
1929 if (info->i18n)
1930 outchar (L_('I'));
1932 if (info->width != 0)
1934 w = _itoa_word (info->width, workend, 10, 0);
1935 while (w < workend)
1936 outchar (*w++);
1939 if (info->prec != -1)
1941 outchar (L_('.'));
1942 w = _itoa_word (info->prec, workend, 10, 0);
1943 while (w < workend)
1944 outchar (*w++);
1947 if (info->spec != L_('\0'))
1948 outchar (info->spec);
1950 all_done:
1951 return done;
1954 /* Group the digits according to the grouping rules of the current locale.
1955 The interpretation of GROUPING is as in `struct lconv' from <locale.h>. */
1956 static CHAR_T *
1957 internal_function
1958 group_number (CHAR_T *w, CHAR_T *rear_ptr, const char *grouping,
1959 #ifdef COMPILE_WPRINTF
1960 wchar_t thousands_sep
1961 #else
1962 const char *thousands_sep
1963 #endif
1966 int len;
1967 CHAR_T *src, *s;
1968 #ifndef COMPILE_WPRINTF
1969 int tlen = strlen (thousands_sep);
1970 #endif
1972 /* We treat all negative values like CHAR_MAX. */
1974 if (*grouping == CHAR_MAX || *grouping <= 0)
1975 /* No grouping should be done. */
1976 return w;
1978 len = *grouping++;
1980 /* Copy existing string so that nothing gets overwritten. */
1981 src = (CHAR_T *) alloca ((rear_ptr - w) * sizeof (CHAR_T));
1982 s = (CHAR_T *) __mempcpy (src, w,
1983 (rear_ptr - w) * sizeof (CHAR_T));
1984 w = rear_ptr;
1986 /* Process all characters in the string. */
1987 while (s > src)
1989 *--w = *--s;
1991 if (--len == 0 && s > src)
1993 /* A new group begins. */
1994 #ifdef COMPILE_WPRINTF
1995 *--w = thousands_sep;
1996 #else
1997 int cnt = tlen;
1999 *--w = thousands_sep[--cnt];
2000 while (cnt > 0);
2001 #endif
2003 if (*grouping == CHAR_MAX
2004 #if CHAR_MIN < 0
2005 || *grouping < 0
2006 #endif
2009 /* No further grouping to be done.
2010 Copy the rest of the number. */
2012 *--w = *--s;
2013 while (s > src);
2014 break;
2016 else if (*grouping != '\0')
2017 /* The previous grouping repeats ad infinitum. */
2018 len = *grouping++;
2019 else
2020 len = grouping[-1];
2023 return w;
2026 /* Helper "class" for `fprintf to unbuffered': creates a temporary buffer. */
2027 struct helper_file
2029 struct _IO_FILE_plus _f;
2030 #ifdef COMPILE_WPRINTF
2031 struct _IO_wide_data _wide_data;
2032 #endif
2033 _IO_FILE *_put_stream;
2034 #ifdef _IO_MTSAFE_IO
2035 _IO_lock_t lock;
2036 #endif
2039 static int
2040 _IO_helper_overflow (_IO_FILE *s, int c)
2042 _IO_FILE *target = ((struct helper_file*) s)->_put_stream;
2043 #ifdef COMPILE_WPRINTF
2044 int used = s->_wide_data->_IO_write_ptr - s->_wide_data->_IO_write_base;
2045 if (used)
2047 _IO_size_t written = _IO_sputn (target, s->_wide_data->_IO_write_base,
2048 used);
2049 s->_wide_data->_IO_write_ptr -= written;
2051 #else
2052 int used = s->_IO_write_ptr - s->_IO_write_base;
2053 if (used)
2055 _IO_size_t written = _IO_sputn (target, s->_IO_write_base, used);
2056 s->_IO_write_ptr -= written;
2058 #endif
2059 return PUTC (c, s);
2062 #ifdef COMPILE_WPRINTF
2063 static const struct _IO_jump_t _IO_helper_jumps =
2065 JUMP_INIT_DUMMY,
2066 JUMP_INIT (finish, INTUSE(_IO_wdefault_finish)),
2067 JUMP_INIT (overflow, _IO_helper_overflow),
2068 JUMP_INIT (underflow, _IO_default_underflow),
2069 JUMP_INIT (uflow, INTUSE(_IO_default_uflow)),
2070 JUMP_INIT (pbackfail, (_IO_pbackfail_t) INTUSE(_IO_wdefault_pbackfail)),
2071 JUMP_INIT (xsputn, INTUSE(_IO_wdefault_xsputn)),
2072 JUMP_INIT (xsgetn, INTUSE(_IO_wdefault_xsgetn)),
2073 JUMP_INIT (seekoff, _IO_default_seekoff),
2074 JUMP_INIT (seekpos, _IO_default_seekpos),
2075 JUMP_INIT (setbuf, _IO_default_setbuf),
2076 JUMP_INIT (sync, _IO_default_sync),
2077 JUMP_INIT (doallocate, INTUSE(_IO_wdefault_doallocate)),
2078 JUMP_INIT (read, _IO_default_read),
2079 JUMP_INIT (write, _IO_default_write),
2080 JUMP_INIT (seek, _IO_default_seek),
2081 JUMP_INIT (close, _IO_default_close),
2082 JUMP_INIT (stat, _IO_default_stat)
2084 #else
2085 static const struct _IO_jump_t _IO_helper_jumps =
2087 JUMP_INIT_DUMMY,
2088 JUMP_INIT (finish, INTUSE(_IO_default_finish)),
2089 JUMP_INIT (overflow, _IO_helper_overflow),
2090 JUMP_INIT (underflow, _IO_default_underflow),
2091 JUMP_INIT (uflow, INTUSE(_IO_default_uflow)),
2092 JUMP_INIT (pbackfail, INTUSE(_IO_default_pbackfail)),
2093 JUMP_INIT (xsputn, INTUSE(_IO_default_xsputn)),
2094 JUMP_INIT (xsgetn, INTUSE(_IO_default_xsgetn)),
2095 JUMP_INIT (seekoff, _IO_default_seekoff),
2096 JUMP_INIT (seekpos, _IO_default_seekpos),
2097 JUMP_INIT (setbuf, _IO_default_setbuf),
2098 JUMP_INIT (sync, _IO_default_sync),
2099 JUMP_INIT (doallocate, INTUSE(_IO_default_doallocate)),
2100 JUMP_INIT (read, _IO_default_read),
2101 JUMP_INIT (write, _IO_default_write),
2102 JUMP_INIT (seek, _IO_default_seek),
2103 JUMP_INIT (close, _IO_default_close),
2104 JUMP_INIT (stat, _IO_default_stat)
2106 #endif
2108 static int
2109 internal_function
2110 buffered_vfprintf (register _IO_FILE *s, const CHAR_T *format,
2111 _IO_va_list args)
2113 CHAR_T buf[_IO_BUFSIZ];
2114 struct helper_file helper;
2115 register _IO_FILE *hp = (_IO_FILE *) &helper._f;
2116 int result, to_flush;
2118 /* Orient the stream. */
2119 #ifdef ORIENT
2120 ORIENT;
2121 #endif
2123 /* Initialize helper. */
2124 helper._put_stream = s;
2125 #ifdef COMPILE_WPRINTF
2126 hp->_wide_data = &helper._wide_data;
2127 _IO_wsetp (hp, buf, buf + sizeof buf / sizeof (CHAR_T));
2128 hp->_mode = 1;
2129 #else
2130 _IO_setp (hp, buf, buf + sizeof buf);
2131 hp->_mode = -1;
2132 #endif
2133 hp->_IO_file_flags = _IO_MAGIC|_IO_NO_READS|_IO_USER_LOCK;
2134 #if _IO_JUMPS_OFFSET
2135 hp->_vtable_offset = 0;
2136 #endif
2137 #ifdef _IO_MTSAFE_IO
2138 hp->_lock = NULL;
2139 #endif
2140 hp->_flags2 = s->_flags2;
2141 _IO_JUMPS (&helper._f) = (struct _IO_jump_t *) &_IO_helper_jumps;
2143 /* Now print to helper instead. */
2144 #ifndef COMPILE_WPRINTF
2145 result = INTUSE(_IO_vfprintf) (hp, format, args);
2146 #else
2147 result = vfprintf (hp, format, args);
2148 #endif
2150 /* Lock stream. */
2151 __libc_cleanup_region_start (1, (void (*) (void *)) &_IO_funlockfile, s);
2152 _IO_flockfile (s);
2154 /* Now flush anything from the helper to the S. */
2155 #ifdef COMPILE_WPRINTF
2156 if ((to_flush = (hp->_wide_data->_IO_write_ptr
2157 - hp->_wide_data->_IO_write_base)) > 0)
2159 if ((int) _IO_sputn (s, hp->_wide_data->_IO_write_base, to_flush)
2160 != to_flush)
2161 result = -1;
2163 #else
2164 if ((to_flush = hp->_IO_write_ptr - hp->_IO_write_base) > 0)
2166 if ((int) _IO_sputn (s, hp->_IO_write_base, to_flush) != to_flush)
2167 result = -1;
2169 #endif
2171 /* Unlock the stream. */
2172 _IO_funlockfile (s);
2173 __libc_cleanup_region_end (0);
2175 return result;
2178 #undef vfprintf
2179 #ifdef COMPILE_WPRINTF
2180 strong_alias (_IO_vfwprintf, __vfwprintf);
2181 ldbl_weak_alias (_IO_vfwprintf, vfwprintf);
2182 #else
2183 ldbl_strong_alias (_IO_vfprintf_internal, vfprintf);
2184 ldbl_hidden_def (_IO_vfprintf_internal, vfprintf)
2185 ldbl_strong_alias (_IO_vfprintf_internal, _IO_vfprintf);
2186 #endif