1 /* Copyright (C) 1991-2006, 2007 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
30 #include <bits/libc-lock.h>
31 #include <locale/localeinfo.h>
34 # define HAVE_LONGLONG
35 # define LONGLONG long long
37 # define LONGLONG long
40 /* Determine whether we have to handle `long long' at all. */
41 #if LONG_MAX == LONG_LONG_MAX
42 # define need_longlong 0
44 # define need_longlong 1
47 /* Determine whether we have to handle `long'. */
48 #if INT_MAX == LONG_MAX
54 /* Those are flags in the conversion format. */
55 #define LONG 0x001 /* l: long or double */
56 #define LONGDBL 0x002 /* L: long long or long double */
57 #define SHORT 0x004 /* h: short */
58 #define SUPPRESS 0x008 /* *: suppress assignment */
59 #define POINTER 0x010 /* weird %p pointer (`fake hex') */
60 #define NOSKIP 0x020 /* do not skip blanks */
61 #define WIDTH 0x040 /* width was given */
62 #define GROUP 0x080 /* ': group numbers */
63 #define MALLOC 0x100 /* a: malloc strings */
64 #define CHAR 0x200 /* hh: char */
65 #define I18N 0x400 /* I: use locale's digits */
68 #include <locale/localeinfo.h>
73 #define va_list _IO_va_list
76 # define ungetc(c, s) ((void) (c == WEOF \
78 INTUSE(_IO_sputbackwc) (s, c))))
79 # define ungetc_not_eof(c, s) ((void) (--read_in, \
80 INTUSE(_IO_sputbackwc) (s, c)))
81 # define inchar() (c == WEOF ? ((errno = inchar_errno), WEOF) \
82 : ((c = _IO_getwc_unlocked (s)), \
85 : (size_t) (inchar_errno = errno)), c))
87 # define MEMCPY(d, s, n) __wmemcpy (d, s, n)
88 # define ISSPACE(Ch) iswspace (Ch)
89 # define ISDIGIT(Ch) iswdigit (Ch)
90 # define ISXDIGIT(Ch) iswxdigit (Ch)
91 # define TOLOWER(Ch) towlower (Ch)
92 # define ORIENT if (_IO_fwide (s, 1) != 1) return WEOF
93 # define __strtoll_internal __wcstoll_internal
94 # define __strtoull_internal __wcstoull_internal
95 # define __strtol_internal __wcstol_internal
96 # define __strtoul_internal __wcstoul_internal
97 # define __strtold_internal __wcstold_internal
98 # define __strtod_internal __wcstod_internal
99 # define __strtof_internal __wcstof_internal
101 # define L_(Str) L##Str
102 # define CHAR_T wchar_t
103 # define UCHAR_T unsigned int
104 # define WINT_T wint_t
108 # define ungetc(c, s) ((void) ((int) c == EOF \
110 INTUSE(_IO_sputbackc) (s, (unsigned char) c))))
111 # define ungetc_not_eof(c, s) ((void) (--read_in, \
112 INTUSE(_IO_sputbackc) (s, (unsigned char) c)))
113 # define inchar() (c == EOF ? ((errno = inchar_errno), EOF) \
114 : ((c = _IO_getc_unlocked (s)), \
117 : (size_t) (inchar_errno = errno)), c))
118 # define MEMCPY(d, s, n) memcpy (d, s, n)
119 # define ISSPACE(Ch) __isspace_l (Ch, loc)
120 # define ISDIGIT(Ch) __isdigit_l (Ch, loc)
121 # define ISXDIGIT(Ch) __isxdigit_l (Ch, loc)
122 # define TOLOWER(Ch) __tolower_l ((unsigned char) (Ch), loc)
123 # define ORIENT if (_IO_vtable_offset (s) == 0 \
124 && _IO_fwide (s, -1) != -1) \
129 # define UCHAR_T unsigned char
133 #define encode_error() do { \
135 __set_errno (EILSEQ); \
138 #define conv_error() do { \
142 #define input_error() do { \
144 if (done == 0) done = EOF; \
147 #define ARGCHECK(s, format) \
150 /* Check file argument for consistence. */ \
151 CHECK_FILE (s, EOF); \
152 if (s->_flags & _IO_NO_READS) \
154 __set_errno (EBADF); \
157 else if (format == NULL) \
163 #define LOCK_STREAM(S) \
164 __libc_cleanup_region_start (1, (void (*) (void *)) &_IO_funlockfile, (S)); \
166 #define UNLOCK_STREAM(S) \
167 _IO_funlockfile (S); \
168 __libc_cleanup_region_end (0)
171 /* Read formatted input from S according to the format string
172 FORMAT, using the argument list in ARG.
173 Return the number of assignments made, or -1 for an input error. */
174 #ifdef COMPILE_WSCANF
176 _IO_vfwscanf (_IO_FILE
*s
, const wchar_t *format
, _IO_va_list argptr
,
180 _IO_vfscanf_internal (_IO_FILE
*s
, const char *format
, _IO_va_list argptr
,
185 register const CHAR_T
*f
= format
;
186 register UCHAR_T fc
; /* Current character of the format. */
187 register WINT_T done
= 0; /* Assignments done. */
188 register size_t read_in
= 0; /* Chars read in. */
189 register WINT_T c
= 0; /* Last char read. */
190 register int width
; /* Maximum field width. */
191 register int flags
; /* Modifiers for current format element. */
193 #ifndef COMPILE_WSCANF
194 __locale_t loc
= _NL_CURRENT_LOCALE
;
195 struct locale_data
*const curctype
= loc
->__locales
[LC_CTYPE
];
198 /* Errno of last failed inchar call. */
199 int inchar_errno
= 0;
200 /* Status for reading F-P nums. */
201 char got_dot
, got_e
, negative
;
202 /* If a [...] is a [^...]. */
204 #define exp_char not_in
205 /* Base for integral numbers. */
207 /* Signedness for integral numbers. */
209 #define is_hexa number_signed
210 /* Decimal point character. */
211 #ifdef COMPILE_WSCANF
216 /* The thousands character of the current locale. */
217 #ifdef COMPILE_WSCANF
220 const char *thousands
;
222 /* State for the conversions. */
224 /* Integral holding variables. */
228 unsigned long long int uq
;
230 unsigned long int ul
;
232 /* Character-buffer pointer. */
234 wchar_t *wstr
= NULL
;
235 char **strptr
= NULL
;
237 /* We must not react on white spaces immediately because they can
238 possibly be matched even if in the input stream no character is
239 available anymore. */
241 /* Nonzero if we are reading a pointer. */
244 CHAR_T
*tw
; /* Temporary pointer. */
245 CHAR_T
*wp
= NULL
; /* Workspace. */
246 size_t wpmax
= 0; /* Maximal size of workspace. */
247 size_t wpsize
; /* Currently used bytes in workspace. */
251 if (wpsize == wpmax) \
254 wpmax = (UCHAR_MAX + 1 > 2 * wpmax ? UCHAR_MAX + 1 : 2 * wpmax); \
255 wp = (CHAR_T *) alloca (wpmax * sizeof (wchar_t)); \
257 MEMCPY (wp, old, wpsize); \
259 wp[wpsize++] = (Ch); \
264 __va_copy (arg
, argptr
);
266 arg
= (va_list) argptr
;
273 ARGCHECK (s
, format
);
276 #ifndef COMPILE_WSCANF
277 struct locale_data
*const curnumeric
= loc
->__locales
[LC_NUMERIC
];
280 /* Figure out the decimal point character. */
281 #ifdef COMPILE_WSCANF
282 decimal
= _NL_CURRENT_WORD (LC_NUMERIC
, _NL_NUMERIC_DECIMAL_POINT_WC
);
284 decimal
= curnumeric
->values
[_NL_ITEM_INDEX (DECIMAL_POINT
)].string
;
286 /* Figure out the thousands separator character. */
287 #ifdef COMPILE_WSCANF
288 thousands
= _NL_CURRENT_WORD (LC_NUMERIC
, _NL_NUMERIC_THOUSANDS_SEP_WC
);
290 thousands
= curnumeric
->values
[_NL_ITEM_INDEX (THOUSANDS_SEP
)].string
;
291 if (*thousands
== '\0')
296 /* Lock the stream. */
300 #ifndef COMPILE_WSCANF
301 /* From now on we use `state' to convert the format string. */
302 memset (&state
, '\0', sizeof (state
));
305 /* Run through the format string. */
309 /* Extract the next argument, which is of type TYPE.
310 For a %N$... spec, this is the Nth argument from the beginning;
311 otherwise it is the next argument after the state now in ARG. */
313 # define ARG(type) (argpos == 0 ? va_arg (arg, type) : \
314 ({ unsigned int pos = argpos; \
316 __va_copy (arg, argptr); \
318 (void) va_arg (arg, void *); \
319 va_arg (arg, type); \
323 /* XXX Possible optimization. */
324 # define ARG(type) (argpos == 0 ? va_arg (arg, type) : \
325 ({ va_list arg = (va_list) argptr; \
326 arg = (va_list) ((char *) arg \
328 * __va_rounded_size (void *)); \
329 va_arg (arg, type); \
332 # define ARG(type) (argpos == 0 ? va_arg (arg, type) : \
333 ({ unsigned int pos = argpos; \
334 va_list arg = (va_list) argptr; \
336 (void) va_arg (arg, void *); \
337 va_arg (arg, type); \
342 #ifndef COMPILE_WSCANF
343 if (!isascii ((unsigned char) *f
))
345 /* Non-ASCII, may be a multibyte. */
346 int len
= __mbrlen (f
, strlen (f
), &state
);
352 if (__builtin_expect (c
== EOF
, 0))
354 else if (c
!= (unsigned char) *f
++)
356 ungetc_not_eof (c
, s
);
369 /* Remember to skip spaces. */
376 /* Read a character. */
379 /* Characters other than format specs must just match. */
380 if (__builtin_expect (c
== EOF
, 0))
383 /* We saw white space char as the last character in the format
384 string. Now it's time to skip all leading white space. */
388 if (__builtin_expect (inchar () == EOF
, 0))
393 if (__builtin_expect (c
!= fc
, 0))
402 /* This is the start of the conversion string. */
405 /* Not yet decided whether we read a pointer or not. */
408 /* Initialize state of modifiers. */
411 /* Prepare temporary buffer. */
414 /* Check for a positional parameter specification. */
415 if (ISDIGIT ((UCHAR_T
) *f
))
417 argpos
= (UCHAR_T
) *f
++ - L_('0');
418 while (ISDIGIT ((UCHAR_T
) *f
))
419 argpos
= argpos
* 10 + ((UCHAR_T
) *f
++ - L_('0'));
424 /* Oops; that was actually the field width. */
432 /* Check for the assignment-suppressing, the number grouping flag,
433 and the signal to use the locale's digit representation. */
434 while (*f
== L_('*') || *f
== L_('\'') || *f
== L_('I'))
448 /* We have seen width. */
449 if (ISDIGIT ((UCHAR_T
) *f
))
452 /* Find the maximum field width. */
454 while (ISDIGIT ((UCHAR_T
) *f
))
457 width
+= (UCHAR_T
) *f
++ - L_('0');
463 /* Check for type modifiers. */
467 /* ints are short ints or chars. */
479 /* A double `l' is equivalent to an `L'. */
481 flags
|= LONGDBL
| LONG
;
484 /* ints are long ints. */
489 /* doubles are long doubles, and ints are long long ints. */
490 flags
|= LONGDBL
| LONG
;
493 /* The `a' is used as a flag only if followed by `s', `S' or
495 if (*f
!= L_('s') && *f
!= L_('S') && *f
!= L_('['))
500 /* String conversions (%s, %[) take a `char **'
501 arg and fill it in with a malloc'd pointer. */
505 if (need_longlong
&& sizeof (size_t) > sizeof (unsigned long int))
507 else if (sizeof (size_t) > sizeof (unsigned int))
511 if (need_longlong
&& sizeof (uintmax_t) > sizeof (unsigned long int))
513 else if (sizeof (uintmax_t) > sizeof (unsigned int))
517 if (need_longlong
&& sizeof (ptrdiff_t) > sizeof (long int))
519 else if (sizeof (ptrdiff_t) > sizeof (int))
523 /* Not a recognized modifier. Backup. */
528 /* End of the format string? */
529 if (__builtin_expect (*f
== L_('\0'), 0))
532 /* Find the conversion specifier. */
534 if (skip_space
|| (fc
!= L_('[') && fc
!= L_('c')
535 && fc
!= L_('C') && fc
!= L_('n')))
537 /* Eat whitespace. */
538 int save_errno
= errno
;
541 if (__builtin_expect (inchar () == EOF
&& errno
== EINTR
, 0))
551 case L_('%'): /* Must match a literal '%'. */
553 if (__builtin_expect (c
== EOF
, 0))
555 if (__builtin_expect (c
!= fc
, 0))
557 ungetc_not_eof (c
, s
);
562 case L_('n'): /* Answer number of assignments done. */
563 /* Corrigendum 1 to ISO C 1990 describes the allowed flags
564 with the 'n' conversion specifier. */
565 if (!(flags
& SUPPRESS
))
567 /* Don't count the read-ahead. */
568 if (need_longlong
&& (flags
& LONGDBL
))
569 *ARG (long long int *) = read_in
;
570 else if (need_long
&& (flags
& LONG
))
571 *ARG (long int *) = read_in
;
572 else if (flags
& SHORT
)
573 *ARG (short int *) = read_in
;
574 else if (!(flags
& CHAR
))
575 *ARG (int *) = read_in
;
577 *ARG (char *) = read_in
;
579 #ifdef NO_BUG_IN_ISO_C_CORRIGENDUM_1
580 /* We have a severe problem here. The ISO C standard
581 contradicts itself in explaining the effect of the %n
582 format in `scanf'. While in ISO C:1990 and the ISO C
583 Amendement 1:1995 the result is described as
585 Execution of a %n directive does not effect the
586 assignment count returned at the completion of
587 execution of the f(w)scanf function.
589 in ISO C Corrigendum 1:1994 the following was added:
592 Add the following fourth example:
595 int d1, d2, n1, n2, i;
596 i = sscanf("123", "%d%n%n%d", &d1, &n1, &n2, &d2);
597 the value 123 is assigned to d1 and the value3 to n1.
598 Because %n can never get an input failure the value
599 of 3 is also assigned to n2. The value of d2 is not
600 affected. The value 3 is assigned to i.
602 We go for now with the historically correct code from ISO C,
603 i.e., we don't count the %n assignments. When it ever
604 should proof to be wrong just remove the #ifdef above. */
610 case L_('c'): /* Match characters. */
611 if ((flags
& LONG
) == 0)
613 if (!(flags
& SUPPRESS
))
621 if (__builtin_expect (c
== EOF
, 0))
627 #ifdef COMPILE_WSCANF
628 /* We have to convert the wide character(s) into multibyte
629 characters and store the result. */
630 memset (&state
, '\0', sizeof (state
));
636 n
= __wcrtomb (!(flags
& SUPPRESS
) ? str
: NULL
, c
, &state
);
637 if (__builtin_expect (n
== (size_t) -1, 0))
638 /* No valid wide character. */
641 /* Increment the output pointer. Even if we don't
645 while (--width
> 0 && inchar () != EOF
);
647 if (!(flags
& SUPPRESS
))
651 while (--width
> 0 && inchar () != EOF
);
654 while (--width
> 0 && inchar () != EOF
);
657 if (!(flags
& SUPPRESS
))
664 if (!(flags
& SUPPRESS
))
666 wstr
= ARG (wchar_t *);
672 if (__builtin_expect (c
== EOF
, 0))
675 #ifdef COMPILE_WSCANF
676 /* Just store the incoming wide characters. */
677 if (!(flags
& SUPPRESS
))
681 while (--width
> 0 && inchar () != EOF
);
684 while (--width
> 0 && inchar () != EOF
);
687 /* We have to convert the multibyte input sequence to wide
692 memset (&cstate
, '\0', sizeof (cstate
));
696 /* This is what we present the mbrtowc function first. */
703 n
= __mbrtowc (!(flags
& SUPPRESS
) ? wstr
: NULL
,
706 if (n
== (size_t) -2)
708 /* Possibly correct character, just not enough
710 if (__builtin_expect (inchar () == EOF
, 0))
717 if (__builtin_expect (n
!= 1, 0))
720 /* We have a match. */
724 /* Advance the result pointer. */
727 while (--width
> 0 && inchar () != EOF
);
731 if (!(flags
& SUPPRESS
))
736 case L_('s'): /* Read a string. */
739 #define STRING_ARG(Str, Type) \
740 do if (!(flags & SUPPRESS)) \
742 if (flags & MALLOC) \
744 /* The string is to be stored in a malloc'd buffer. */ \
745 strptr = ARG (char **); \
746 if (strptr == NULL) \
748 /* Allocate an initial buffer. */ \
750 *strptr = (char *) malloc (strsize * sizeof (Type)); \
751 Str = (Type *) *strptr; \
754 Str = ARG (Type *); \
758 STRING_ARG (str
, char);
761 if (__builtin_expect (c
== EOF
, 0))
764 #ifdef COMPILE_WSCANF
765 memset (&state
, '\0', sizeof (state
));
772 ungetc_not_eof (c
, s
);
776 #ifdef COMPILE_WSCANF
777 /* This is quite complicated. We have to convert the
778 wide characters into multibyte characters and then
783 if (!(flags
& SUPPRESS
) && (flags
& MALLOC
)
784 && str
+ MB_CUR_MAX
>= *strptr
+ strsize
)
786 /* We have to enlarge the buffer if the `a' flag
788 size_t strleng
= str
- *strptr
;
791 newstr
= (char *) realloc (*strptr
, strsize
* 2);
794 /* Can't allocate that much. Last-ditch
796 newstr
= (char *) realloc (*strptr
,
797 strleng
+ MB_CUR_MAX
);
800 /* We lose. Oh well. Terminate the
801 string and stop converting,
802 so at least we don't skip any input. */
803 ((char *) (*strptr
))[strleng
] = '\0';
810 str
= newstr
+ strleng
;
811 strsize
= strleng
+ MB_CUR_MAX
;
817 str
= newstr
+ strleng
;
822 n
= __wcrtomb (!(flags
& SUPPRESS
) ? str
: NULL
, c
,
824 if (__builtin_expect (n
== (size_t) -1, 0))
827 assert (n
<= MB_CUR_MAX
);
832 if (!(flags
& SUPPRESS
))
836 && (char *) str
== *strptr
+ strsize
)
838 /* Enlarge the buffer. */
839 str
= (char *) realloc (*strptr
, 2 * strsize
);
842 /* Can't allocate that much. Last-ditch
844 str
= (char *) realloc (*strptr
, strsize
+ 1);
847 /* We lose. Oh well. Terminate the
848 string and stop converting,
849 so at least we don't skip any input. */
850 ((char *) (*strptr
))[strsize
- 1] = '\0';
856 *strptr
= (char *) str
;
863 *strptr
= (char *) str
;
871 while ((width
<= 0 || --width
> 0) && inchar () != EOF
);
873 if (!(flags
& SUPPRESS
))
875 #ifdef COMPILE_WSCANF
876 /* We have to emit the code to get into the initial
878 char buf
[MB_LEN_MAX
];
879 size_t n
= __wcrtomb (buf
, L
'\0', &state
);
880 if (n
> 0 && (flags
& MALLOC
)
881 && str
+ n
>= *strptr
+ strsize
)
883 /* Enlarge the buffer. */
884 size_t strleng
= str
- *strptr
;
887 newstr
= (char *) realloc (*strptr
, strleng
+ n
+ 1);
890 /* We lose. Oh well. Terminate the string
891 and stop converting, so at least we don't
893 ((char *) (*strptr
))[strleng
] = '\0';
900 str
= newstr
+ strleng
;
901 strsize
= strleng
+ n
+ 1;
905 str
= __mempcpy (str
, buf
, n
);
909 if ((flags
& MALLOC
) && str
- *strptr
!= strsize
)
911 char *cp
= (char *) realloc (*strptr
, str
- *strptr
);
924 #ifndef COMPILE_WSCANF
928 /* Wide character string. */
929 STRING_ARG (wstr
, wchar_t);
932 if (__builtin_expect (c
== EOF
, 0))
935 #ifndef COMPILE_WSCANF
936 memset (&cstate
, '\0', sizeof (cstate
));
943 ungetc_not_eof (c
, s
);
947 #ifdef COMPILE_WSCANF
949 if (!(flags
& SUPPRESS
))
953 && wstr
== (wchar_t *) *strptr
+ strsize
)
955 /* Enlarge the buffer. */
956 wstr
= (wchar_t *) realloc (*strptr
,
961 /* Can't allocate that much. Last-ditch
963 wstr
= (wchar_t *) realloc (*strptr
,
968 /* We lose. Oh well. Terminate the string
969 and stop converting, so at least we don't
971 ((wchar_t *) (*strptr
))[strsize
- 1] = L
'\0';
977 *strptr
= (char *) wstr
;
984 *strptr
= (char *) wstr
;
1000 n
= __mbrtowc (!(flags
& SUPPRESS
) ? wstr
: NULL
,
1003 if (n
== (size_t) -2)
1005 /* Possibly correct character, just not enough
1007 if (__builtin_expect (inchar () == EOF
, 0))
1014 if (__builtin_expect (n
!= 1, 0))
1017 /* We have a match. */
1022 if (!(flags
& SUPPRESS
) && (flags
& MALLOC
)
1023 && wstr
== (wchar_t *) *strptr
+ strsize
)
1025 /* Enlarge the buffer. */
1026 wstr
= (wchar_t *) realloc (*strptr
,
1028 * sizeof (wchar_t)));
1031 /* Can't allocate that much. Last-ditch effort. */
1032 wstr
= (wchar_t *) realloc (*strptr
,
1034 * sizeof (wchar_t)));
1037 /* We lose. Oh well. Terminate the
1038 string and stop converting, so at
1039 least we don't skip any input. */
1040 ((wchar_t *) (*strptr
))[strsize
- 1] = L
'\0';
1046 *strptr
= (char *) wstr
;
1053 *strptr
= (char *) wstr
;
1061 while ((width
<= 0 || --width
> 0) && inchar () != EOF
);
1063 if (!(flags
& SUPPRESS
))
1067 if ((flags
& MALLOC
) && wstr
- (wchar_t *) *strptr
!= strsize
)
1069 wchar_t *cp
= (wchar_t *) realloc (*strptr
,
1071 - (wchar_t *) *strptr
)
1072 * sizeof(wchar_t)));
1074 *strptr
= (char *) cp
;
1082 case L_('x'): /* Hexadecimal integer. */
1083 case L_('X'): /* Ditto. */
1088 case L_('o'): /* Octal integer. */
1093 case L_('u'): /* Unsigned decimal integer. */
1098 case L_('d'): /* Signed decimal integer. */
1103 case L_('i'): /* Generic number. */
1109 if (__builtin_expect (c
== EOF
, 0))
1112 /* Check for a sign. */
1113 if (c
== L_('-') || c
== L_('+'))
1121 /* Look for a leading indication of base. */
1122 if (width
!= 0 && c
== L_('0'))
1130 if (width
!= 0 && TOLOWER (c
) == L_('x'))
1148 if (base
== 10 && __builtin_expect ((flags
& I18N
) != 0, 0))
1153 #ifdef COMPILE_WSCANF
1154 const wchar_t *wcdigits
[10];
1155 const wchar_t *wcdigits_extended
[10];
1157 const char *mbdigits
[10];
1158 const char *mbdigits_extended
[10];
1160 /* "to_inpunct" is a map from ASCII digits to their
1161 equivalent in locale. This is defined for locales
1162 which use an extra digits set. */
1163 wctrans_t map
= __wctrans ("to_inpunct");
1167 #ifdef COMPILE_WSCANF
1168 to_level
= _NL_CURRENT_WORD (LC_CTYPE
,
1169 _NL_CTYPE_INDIGITS_WC_LEN
) - 1;
1171 to_level
= (uint32_t) curctype
->values
[_NL_ITEM_INDEX (_NL_CTYPE_INDIGITS_MB_LEN
)].word
- 1;
1174 /* Get the alternative digit forms if there are any. */
1175 if (__builtin_expect (map
!= NULL
, 0))
1177 /* Adding new level for extra digits set in locale file. */
1180 for (n
= 0; n
< 10; ++n
)
1182 #ifdef COMPILE_WSCANF
1183 wcdigits
[n
] = (const wchar_t *)
1184 _NL_CURRENT (LC_CTYPE
, _NL_CTYPE_INDIGITS0_WC
+ n
);
1186 wchar_t *wc_extended
= (wchar_t *)
1187 alloca ((to_level
+ 2) * sizeof (wchar_t));
1188 __wmemcpy (wc_extended
, wcdigits
[n
], to_level
);
1189 wc_extended
[to_level
] = __towctrans (L
'0' + n
, map
);
1190 wc_extended
[to_level
+ 1] = '\0';
1191 wcdigits_extended
[n
] = wc_extended
;
1194 = curctype
->values
[_NL_CTYPE_INDIGITS0_MB
+ n
].string
;
1196 /* Get the equivalent wide char in map. */
1197 wint_t extra_wcdigit
= __towctrans (L
'0' + n
, map
);
1199 /* Convert it to multibyte representation. */
1201 memset (&state
, '\0', sizeof (state
));
1203 char extra_mbdigit
[MB_LEN_MAX
];
1205 = __wcrtomb (extra_mbdigit
, extra_wcdigit
, &state
);
1207 if (mblen
== (size_t) -1)
1209 /* Ignore this new level. */
1214 /* Calculate the length of mbdigits[n]. */
1215 const char *last_char
= mbdigits
[n
];
1216 for (level
= 0; level
< to_level
; ++level
)
1217 last_char
= strchr (last_char
, '\0') + 1;
1219 size_t mbdigits_len
= last_char
- mbdigits
[n
];
1221 /* Allocate memory for extended multibyte digit. */
1223 mb_extended
= (char *) alloca (mbdigits_len
+ mblen
+ 1);
1225 /* And get the mbdigits + extra_digit string. */
1226 *(char *) __mempcpy (__mempcpy (mb_extended
, mbdigits
[n
],
1228 extra_mbdigit
, mblen
) = '\0';
1229 mbdigits_extended
[n
] = mb_extended
;
1234 /* Read the number into workspace. */
1235 while (c
!= EOF
&& width
!= 0)
1237 /* In this round we get the pointer to the digit strings
1238 and also perform the first round of comparisons. */
1239 for (n
= 0; n
< 10; ++n
)
1241 /* Get the string for the digits with value N. */
1242 #ifdef COMPILE_WSCANF
1243 if (__builtin_expect (map
!= NULL
, 0))
1244 wcdigits
[n
] = wcdigits_extended
[n
];
1246 wcdigits
[n
] = (const wchar_t *)
1247 _NL_CURRENT (LC_CTYPE
, _NL_CTYPE_INDIGITS0_WC
+ n
);
1248 wcdigits
[n
] += from_level
;
1250 if (c
== (wint_t) *wcdigits
[n
])
1252 to_level
= from_level
;
1256 /* Advance the pointer to the next string. */
1260 int avail
= width
> 0 ? width
: INT_MAX
;
1262 if (__builtin_expect (map
!= NULL
, 0))
1263 mbdigits
[n
] = mbdigits_extended
[n
];
1266 = curctype
->values
[_NL_CTYPE_INDIGITS0_MB
+ n
].string
;
1268 for (level
= 0; level
< from_level
; level
++)
1269 mbdigits
[n
] = strchr (mbdigits
[n
], '\0') + 1;
1272 while ((unsigned char) *cmpp
== c
&& avail
> 0)
1274 if (*++cmpp
== '\0')
1278 if ((c
= inchar ()) == EOF
)
1288 to_level
= from_level
;
1292 /* We are pushing all read characters back. */
1293 if (cmpp
> mbdigits
[n
])
1296 while (--cmpp
> mbdigits
[n
])
1297 ungetc_not_eof ((unsigned char) *cmpp
, s
);
1298 c
= (unsigned char) *cmpp
;
1301 /* Advance the pointer to the next string. */
1302 mbdigits
[n
] = strchr (mbdigits
[n
], '\0') + 1;
1308 /* Have not yet found the digit. */
1309 for (level
= from_level
+ 1; level
<= to_level
; ++level
)
1311 /* Search all ten digits of this level. */
1312 for (n
= 0; n
< 10; ++n
)
1314 #ifdef COMPILE_WSCANF
1315 if (c
== (wint_t) *wcdigits
[n
])
1318 /* Advance the pointer to the next string. */
1322 int avail
= width
> 0 ? width
: INT_MAX
;
1325 while ((unsigned char) *cmpp
== c
&& avail
> 0)
1327 if (*++cmpp
== '\0')
1331 if ((c
= inchar ()) == EOF
)
1344 /* We are pushing all read characters back. */
1345 if (cmpp
> mbdigits
[n
])
1348 while (--cmpp
> mbdigits
[n
])
1349 ungetc_not_eof ((unsigned char) *cmpp
, s
);
1350 c
= (unsigned char) *cmpp
;
1353 /* Advance the pointer to the next string. */
1354 mbdigits
[n
] = strchr (mbdigits
[n
], '\0') + 1;
1370 else if ((flags
& GROUP
)
1371 #ifdef COMPILE_WSCANF
1372 && thousands
!= L
'\0'
1374 && thousands
!= NULL
1378 /* Try matching against the thousands separator. */
1379 #ifdef COMPILE_WSCANF
1383 const char *cmpp
= thousands
;
1384 int avail
= width
> 0 ? width
: INT_MAX
;
1386 while ((unsigned char) *cmpp
== c
&& avail
> 0)
1389 if (*++cmpp
== '\0')
1393 if ((c
= inchar ()) == EOF
)
1401 /* We are pushing all read characters back. */
1402 if (cmpp
> thousands
)
1404 wpsize
-= cmpp
- thousands
;
1406 while (--cmpp
> thousands
)
1407 ungetc_not_eof ((unsigned char) *cmpp
, s
);
1408 c
= (unsigned char) *cmpp
;
1416 /* The last thousands character will be added back by
1432 /* Read the number into workspace. */
1433 while (c
!= EOF
&& width
!= 0)
1440 else if (!ISDIGIT (c
) || (int) (c
- L_('0')) >= base
)
1442 if (base
== 10 && (flags
& GROUP
)
1443 #ifdef COMPILE_WSCANF
1444 && thousands
!= L
'\0'
1446 && thousands
!= NULL
1450 /* Try matching against the thousands separator. */
1451 #ifdef COMPILE_WSCANF
1455 const char *cmpp
= thousands
;
1456 int avail
= width
> 0 ? width
: INT_MAX
;
1458 while ((unsigned char) *cmpp
== c
&& avail
> 0)
1461 if (*++cmpp
== '\0')
1465 if ((c
= inchar ()) == EOF
)
1473 /* We are pushing all read characters back. */
1474 if (cmpp
> thousands
)
1476 wpsize
-= cmpp
- thousands
;
1478 while (--cmpp
> thousands
)
1479 ungetc_not_eof ((unsigned char) *cmpp
, s
);
1480 c
= (unsigned char) *cmpp
;
1488 /* The last thousands character will be added back by
1504 || (wpsize
== 1 && (wp
[0] == L_('+') || wp
[0] == L_('-'))))
1506 /* There was no number. If we are supposed to read a pointer
1507 we must recognize "(nil)" as well. */
1508 if (__builtin_expect (wpsize
== 0
1510 && (width
< 0 || width
>= 0)
1512 && TOLOWER (inchar ()) == L_('n')
1513 && TOLOWER (inchar ()) == L_('i')
1514 && TOLOWER (inchar ()) == L_('l')
1515 && inchar () == L_(')'), 1))
1516 /* We must produce the value of a NULL pointer. A single
1517 '0' digit is enough. */
1521 /* The last read character is not part of the number
1529 /* The just read character is not part of the number anymore. */
1532 /* Convert the number. */
1534 if (need_longlong
&& (flags
& LONGDBL
))
1537 num
.q
= __strtoll_internal (wp
, &tw
, base
, flags
& GROUP
);
1539 num
.uq
= __strtoull_internal (wp
, &tw
, base
, flags
& GROUP
);
1544 num
.l
= __strtol_internal (wp
, &tw
, base
, flags
& GROUP
);
1546 num
.ul
= __strtoul_internal (wp
, &tw
, base
, flags
& GROUP
);
1548 if (__builtin_expect (wp
== tw
, 0))
1551 if (!(flags
& SUPPRESS
))
1553 if (! number_signed
)
1555 if (need_longlong
&& (flags
& LONGDBL
))
1556 *ARG (unsigned LONGLONG
int *) = num
.uq
;
1557 else if (need_long
&& (flags
& LONG
))
1558 *ARG (unsigned long int *) = num
.ul
;
1559 else if (flags
& SHORT
)
1560 *ARG (unsigned short int *)
1561 = (unsigned short int) num
.ul
;
1562 else if (!(flags
& CHAR
))
1563 *ARG (unsigned int *) = (unsigned int) num
.ul
;
1565 *ARG (unsigned char *) = (unsigned char) num
.ul
;
1569 if (need_longlong
&& (flags
& LONGDBL
))
1570 *ARG (LONGLONG
int *) = num
.q
;
1571 else if (need_long
&& (flags
& LONG
))
1572 *ARG (long int *) = num
.l
;
1573 else if (flags
& SHORT
)
1574 *ARG (short int *) = (short int) num
.l
;
1575 else if (!(flags
& CHAR
))
1576 *ARG (int *) = (int) num
.l
;
1578 *ARG (signed char *) = (signed char) num
.ul
;
1584 case L_('e'): /* Floating-point numbers. */
1593 if (__builtin_expect (c
== EOF
, 0))
1596 got_dot
= got_e
= 0;
1598 /* Check for a sign. */
1599 if (c
== L_('-') || c
== L_('+'))
1601 negative
= c
== L_('-');
1602 if (__builtin_expect (width
== 0 || inchar () == EOF
, 0))
1603 /* EOF is only an input error before we read any chars. */
1605 if (! ISDIGIT (c
) && TOLOWER (c
) != L_('i')
1606 && TOLOWER (c
) != L_('n'))
1608 #ifdef COMPILE_WSCANF
1609 if (__builtin_expect (c
!= decimal
, 0))
1611 /* This is no valid number. */
1616 /* Match against the decimal point. At this point
1617 we are taking advantage of the fact that we can
1618 push more than one character back. This is
1619 (almost) never necessary since the decimal point
1620 string hopefully never contains more than one
1622 const char *cmpp
= decimal
;
1623 int avail
= width
> 0 ? width
: INT_MAX
;
1625 while ((unsigned char) *cmpp
== c
&& avail
-- > 0)
1626 if (*++cmpp
== '\0')
1630 if (inchar () == EOF
)
1634 if (__builtin_expect (*cmpp
!= '\0', 0))
1636 /* This is no valid number. */
1640 if (cmpp
== decimal
)
1642 c
= (unsigned char) *--cmpp
;
1649 /* Add all the characters. */
1650 for (cmpp
= decimal
; *cmpp
!= '\0'; ++cmpp
)
1651 ADDW ((unsigned char) *cmpp
);
1668 /* Take care for the special arguments "nan" and "inf". */
1669 if (TOLOWER (c
) == L_('n'))
1673 if (__builtin_expect (width
== 0
1675 || TOLOWER (c
) != L_('a'), 0))
1680 if (__builtin_expect (width
== 0
1682 || TOLOWER (c
) != L_('n'), 0))
1690 else if (TOLOWER (c
) == L_('i'))
1692 /* Maybe "inf" or "infinity". */
1694 if (__builtin_expect (width
== 0
1696 || TOLOWER (c
) != L_('n'), 0))
1701 if (__builtin_expect (width
== 0
1703 || TOLOWER (c
) != L_('f'), 0))
1708 /* It is as least "inf". */
1709 if (width
!= 0 && inchar () != EOF
)
1711 if (TOLOWER (c
) == L_('i'))
1715 /* Now we have to read the rest as well. */
1717 if (__builtin_expect (width
== 0
1719 || TOLOWER (c
) != L_('n'), 0))
1724 if (__builtin_expect (width
== 0
1726 || TOLOWER (c
) != L_('i'), 0))
1731 if (__builtin_expect (width
== 0
1733 || TOLOWER (c
) != L_('t'), 0))
1738 if (__builtin_expect (width
== 0
1740 || TOLOWER (c
) != L_('y'), 0))
1755 if (width
!= 0 && c
== L_('0'))
1761 if (width
!= 0 && TOLOWER (c
) == L_('x'))
1763 /* It is a number in hexadecimal format. */
1769 /* Grouping is not allowed. */
1781 else if (!got_e
&& is_hexa
&& ISXDIGIT (c
))
1783 else if (got_e
&& wp
[wpsize
- 1] == exp_char
1784 && (c
== L_('-') || c
== L_('+')))
1786 else if (wpsize
> 0 && !got_e
1787 && (CHAR_T
) TOLOWER (c
) == exp_char
)
1790 got_e
= got_dot
= 1;
1794 #ifdef COMPILE_WSCANF
1795 if (! got_dot
&& c
== decimal
)
1800 else if ((flags
& GROUP
) != 0 && thousands
!= L
'\0'
1801 && ! got_dot
&& c
== thousands
)
1805 /* The last read character is not part of the number
1811 const char *cmpp
= decimal
;
1812 int avail
= width
> 0 ? width
: INT_MAX
;
1816 while ((unsigned char) *cmpp
== c
&& avail
> 0)
1817 if (*++cmpp
== '\0')
1821 if (inchar () == EOF
)
1829 /* Add all the characters. */
1830 for (cmpp
= decimal
; *cmpp
!= '\0'; ++cmpp
)
1831 ADDW ((unsigned char) *cmpp
);
1838 /* Figure out whether it is a thousands separator.
1839 There is one problem: we possibly read more than
1840 one character. We cannot push them back but since
1841 we know that parts of the `decimal' string matched,
1842 we can compare against it. */
1843 const char *cmp2p
= thousands
;
1845 if ((flags
& GROUP
) != 0 && thousands
!= NULL
1848 while (cmp2p
- thousands
< cmpp
- decimal
1849 && *cmp2p
== decimal
[cmp2p
- thousands
])
1851 if (cmp2p
- thousands
== cmpp
- decimal
)
1853 while ((unsigned char) *cmp2p
== c
&& avail
> 0)
1854 if (*++cmp2p
== '\0')
1858 if (inchar () == EOF
)
1865 if (cmp2p
!= NULL
&& *cmp2p
== '\0')
1867 /* Add all the characters. */
1868 for (cmpp
= thousands
; *cmpp
!= '\0'; ++cmpp
)
1869 ADDW ((unsigned char) *cmpp
);
1875 /* The last read character is not part of the number
1886 while (width
!= 0 && inchar () != EOF
);
1888 /* Have we read any character? If we try to read a number
1889 in hexadecimal notation and we have read only the `0x'
1890 prefix this is an error. */
1891 if (__builtin_expect (wpsize
== 0 || (is_hexa
&& wpsize
== 2), 0))
1895 /* Convert the number. */
1897 if ((flags
& LONGDBL
) && !__ldbl_is_dbl
)
1899 long double d
= __strtold_internal (wp
, &tw
, flags
& GROUP
);
1900 if (!(flags
& SUPPRESS
) && tw
!= wp
)
1901 *ARG (long double *) = negative
? -d
: d
;
1903 else if (flags
& (LONG
| LONGDBL
))
1905 double d
= __strtod_internal (wp
, &tw
, flags
& GROUP
);
1906 if (!(flags
& SUPPRESS
) && tw
!= wp
)
1907 *ARG (double *) = negative
? -d
: d
;
1911 float d
= __strtof_internal (wp
, &tw
, flags
& GROUP
);
1912 if (!(flags
& SUPPRESS
) && tw
!= wp
)
1913 *ARG (float *) = negative
? -d
: d
;
1916 if (__builtin_expect (tw
== wp
, 0))
1919 if (!(flags
& SUPPRESS
))
1923 case L_('['): /* Character class. */
1925 STRING_ARG (wstr
, wchar_t);
1927 STRING_ARG (str
, char);
1938 /* There is no width given so there is also no limit on the
1939 number of characters we read. Therefore we set width to
1940 a very high value to make the algorithm easier. */
1943 #ifdef COMPILE_WSCANF
1944 /* Find the beginning and the end of the scanlist. We are not
1945 creating a lookup table since it would have to be too large.
1946 Instead we search each time through the string. This is not
1947 a constant lookup time but who uses this feature deserves to
1949 tw
= (wchar_t *) f
; /* Marks the beginning. */
1954 while ((fc
= *f
++) != L
'\0' && fc
!= L
']');
1956 if (__builtin_expect (fc
== L
'\0', 0))
1958 wp
= (wchar_t *) f
- 1;
1960 /* Fill WP with byte flags indexed by character.
1961 We will use this flag map for matching input characters. */
1962 if (wpmax
< UCHAR_MAX
+ 1)
1964 wpmax
= UCHAR_MAX
+ 1;
1965 wp
= (char *) alloca (wpmax
);
1967 memset (wp
, '\0', UCHAR_MAX
+ 1);
1970 if (fc
== ']' || fc
== '-')
1972 /* If ] or - appears before any char in the set, it is not
1973 the terminator or separator, but the first char in the
1979 while ((fc
= *f
++) != '\0' && fc
!= ']')
1980 if (fc
== '-' && *f
!= '\0' && *f
!= ']'
1981 && (unsigned char) f
[-2] <= (unsigned char) *f
)
1983 /* Add all characters from the one before the '-'
1984 up to (but not including) the next format char. */
1985 for (fc
= (unsigned char) f
[-2]; fc
< (unsigned char) *f
; ++fc
)
1989 /* Add the character to the flag map. */
1992 if (__builtin_expect (fc
== '\0', 0))
1998 size_t now
= read_in
;
1999 #ifdef COMPILE_WSCANF
2000 if (__builtin_expect (inchar () == WEOF
, 0))
2007 /* Test whether it's in the scanlist. */
2011 if (runp
[0] == L
'-' && runp
[1] != '\0' && runp
+ 1 != wp
2013 && (unsigned int) runp
[-1] <= (unsigned int) runp
[1])
2015 /* Match against all characters in between the
2016 first and last character of the sequence. */
2019 for (wc
= runp
[-1] + 1; wc
<= runp
[1]; ++wc
)
2020 if ((wint_t) wc
== c
)
2023 if (wc
<= runp
[1] && !not_in
)
2025 if (wc
<= runp
[1] && not_in
)
2027 /* The current character is not in the
2037 if ((wint_t) *runp
== c
&& !not_in
)
2039 if ((wint_t) *runp
== c
&& not_in
)
2049 if (runp
== wp
&& !not_in
)
2055 if (!(flags
& SUPPRESS
))
2059 if ((flags
& MALLOC
)
2060 && wstr
== (wchar_t *) *strptr
+ strsize
)
2062 /* Enlarge the buffer. */
2063 wstr
= (wchar_t *) realloc (*strptr
,
2065 * sizeof (wchar_t));
2068 /* Can't allocate that much. Last-ditch
2071 realloc (*strptr
, (strsize
+ 1)
2072 * sizeof (wchar_t));
2075 /* We lose. Oh well. Terminate the string
2076 and stop converting, so at least we don't
2078 ((wchar_t *) (*strptr
))[strsize
- 1] = L
'\0';
2084 *strptr
= (char *) wstr
;
2091 *strptr
= (char *) wstr
;
2098 while (--width
> 0 && inchar () != WEOF
);
2101 char buf
[MB_LEN_MAX
];
2105 if (__builtin_expect (inchar () == EOF
, 0))
2108 memset (&cstate
, '\0', sizeof (cstate
));
2112 if (wp
[c
] == not_in
)
2114 ungetc_not_eof (c
, s
);
2119 if (!(flags
& SUPPRESS
))
2123 /* Convert it into a wide character. */
2125 n
= __mbrtowc (wstr
, buf
, 1, &cstate
);
2127 if (n
== (size_t) -2)
2129 /* Possibly correct character, just not enough
2132 assert (cnt
< MB_CUR_MAX
);
2138 if ((flags
& MALLOC
)
2139 && wstr
== (wchar_t *) *strptr
+ strsize
)
2141 /* Enlarge the buffer. */
2142 wstr
= (wchar_t *) realloc (*strptr
,
2144 * sizeof (wchar_t)));
2147 /* Can't allocate that much. Last-ditch
2150 realloc (*strptr
, ((strsize
+ 1)
2151 * sizeof (wchar_t)));
2154 /* We lose. Oh well. Terminate the
2155 string and stop converting,
2156 so at least we don't skip any input. */
2157 ((wchar_t *) (*strptr
))[strsize
- 1] = L
'\0';
2163 *strptr
= (char *) wstr
;
2170 *strptr
= (char *) wstr
;
2180 while (inchar () != EOF
);
2182 if (__builtin_expect (cnt
!= 0, 0))
2183 /* We stopped in the middle of recognizing another
2184 character. That's a problem. */
2188 if (__builtin_expect (now
== read_in
, 0))
2189 /* We haven't succesfully read any character. */
2192 if (!(flags
& SUPPRESS
))
2196 if ((flags
& MALLOC
)
2197 && wstr
- (wchar_t *) *strptr
!= strsize
)
2199 wchar_t *cp
= (wchar_t *)
2200 realloc (*strptr
, ((wstr
- (wchar_t *) *strptr
)
2201 * sizeof(wchar_t)));
2203 *strptr
= (char *) cp
;
2211 size_t now
= read_in
;
2213 if (__builtin_expect (inchar () == EOF
, 0))
2216 #ifdef COMPILE_WSCANF
2218 memset (&state
, '\0', sizeof (state
));
2225 /* Test whether it's in the scanlist. */
2229 if (runp
[0] == L
'-' && runp
[1] != '\0' && runp
+ 1 != wp
2231 && (unsigned int) runp
[-1] <= (unsigned int) runp
[1])
2233 /* Match against all characters in between the
2234 first and last character of the sequence. */
2237 for (wc
= runp
[-1] + 1; wc
<= runp
[1]; ++wc
)
2238 if ((wint_t) wc
== c
)
2241 if (wc
<= runp
[1] && !not_in
)
2243 if (wc
<= runp
[1] && not_in
)
2245 /* The current character is not in the
2255 if ((wint_t) *runp
== c
&& !not_in
)
2257 if ((wint_t) *runp
== c
&& not_in
)
2267 if (runp
== wp
&& !not_in
)
2273 if (!(flags
& SUPPRESS
))
2275 if ((flags
& MALLOC
)
2276 && str
+ MB_CUR_MAX
>= *strptr
+ strsize
)
2278 /* Enlarge the buffer. */
2279 size_t strleng
= str
- *strptr
;
2282 newstr
= (char *) realloc (*strptr
, 2 * strsize
);
2285 /* Can't allocate that much. Last-ditch
2287 newstr
= (char *) realloc (*strptr
,
2288 strleng
+ MB_CUR_MAX
);
2291 /* We lose. Oh well. Terminate the string
2292 and stop converting, so at least we don't
2294 ((char *) (*strptr
))[strleng
] = '\0';
2301 str
= newstr
+ strleng
;
2302 strsize
= strleng
+ MB_CUR_MAX
;
2308 str
= newstr
+ strleng
;
2314 n
= __wcrtomb (!(flags
& SUPPRESS
) ? str
: NULL
, c
, &state
);
2315 if (__builtin_expect (n
== (size_t) -1, 0))
2318 assert (n
<= MB_CUR_MAX
);
2321 while (--width
> 0 && inchar () != WEOF
);
2326 if (wp
[c
] == not_in
)
2328 ungetc_not_eof (c
, s
);
2333 if (!(flags
& SUPPRESS
))
2336 if ((flags
& MALLOC
)
2337 && (char *) str
== *strptr
+ strsize
)
2339 /* Enlarge the buffer. */
2340 size_t newsize
= 2 * strsize
;
2343 str
= (char *) realloc (*strptr
, newsize
);
2346 /* Can't allocate that much. Last-ditch
2348 if (newsize
> strsize
+ 1)
2350 newsize
= strsize
+ 1;
2353 /* We lose. Oh well. Terminate the
2354 string and stop converting,
2355 so at least we don't skip any input. */
2356 ((char *) (*strptr
))[strsize
- 1] = '\0';
2362 *strptr
= (char *) str
;
2369 while (--width
> 0 && inchar () != EOF
);
2372 if (__builtin_expect (now
== read_in
, 0))
2373 /* We haven't succesfully read any character. */
2376 if (!(flags
& SUPPRESS
))
2378 #ifdef COMPILE_WSCANF
2379 /* We have to emit the code to get into the initial
2381 char buf
[MB_LEN_MAX
];
2382 size_t n
= __wcrtomb (buf
, L
'\0', &state
);
2383 if (n
> 0 && (flags
& MALLOC
)
2384 && str
+ n
>= *strptr
+ strsize
)
2386 /* Enlarge the buffer. */
2387 size_t strleng
= str
- *strptr
;
2390 newstr
= (char *) realloc (*strptr
, strleng
+ n
+ 1);
2393 /* We lose. Oh well. Terminate the string
2394 and stop converting, so at least we don't
2396 ((char *) (*strptr
))[strleng
] = '\0';
2403 str
= newstr
+ strleng
;
2404 strsize
= strleng
+ n
+ 1;
2408 str
= __mempcpy (str
, buf
, n
);
2412 if ((flags
& MALLOC
) && str
- *strptr
!= strsize
)
2414 char *cp
= (char *) realloc (*strptr
, str
- *strptr
);
2424 case L_('p'): /* Generic pointer. */
2426 /* A PTR must be the same size as a `long int'. */
2427 flags
&= ~(SHORT
|LONGDBL
);
2435 /* If this is an unknown format character punt. */
2440 /* The last thing we saw int the format string was a white space.
2441 Consume the last white spaces. */
2446 while (ISSPACE (c
));
2451 /* Unlock stream. */
2460 #ifdef COMPILE_WSCANF
2462 __vfwscanf (FILE *s
, const wchar_t *format
, va_list argptr
)
2464 return _IO_vfwscanf (s
, format
, argptr
, NULL
);
2466 ldbl_weak_alias (__vfwscanf
, vfwscanf
)
2469 ___vfscanf (FILE *s
, const char *format
, va_list argptr
)
2471 return _IO_vfscanf_internal (s
, format
, argptr
, NULL
);
2473 ldbl_strong_alias (_IO_vfscanf_internal
, _IO_vfscanf
)
2474 ldbl_strong_alias (___vfscanf
, __vfscanf
)
2475 ldbl_hidden_def (___vfscanf
, __vfscanf
)
2476 ldbl_weak_alias (___vfscanf
, vfscanf
)