1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

Add __vfscanf_internal and __vfwscanf_internal with flags arguments.

There are two flags currently defined: SCANF_LDBL_IS_DBL is the mode
used by __nldbl_ scanf variants, and SCANF_ISOC99_A is the mode used
by __isoc99_ scanf variants.  In this patch, the new functions honor
these flag bits if they're set, but they still also look at the
corresponding bits of environmental state, and callers all pass zero.

The new functions do *not* have the "errp" argument possessed by
_IO_vfscanf and _IO_vfwscanf.  All internal callers passed NULL for
that argument.  External callers could theoretically exist, so I
preserved wrappers, but they are flagged as compat symbols and they
don't preserve the three-way distinction among types of errors that
was formerly exposed.  These functions probably should have been in
the list of deprecated _IO_ symbols in 2.27 NEWS -- they're not just
aliases for vfscanf and vfwscanf.

(It was necessary to introduce ldbl_compat_symbol for _IO_vfscanf.
Please check that part of the patch very carefully, I am still not
confident I understand all of the details of ldbl-opt.)

This patch also introduces helper inlines in libio/strfile.h that
encapsulate the process of initializing an _IO_strfile object for
reading.  This allows us to call __vfscanf_internal directly from
sscanf, and __vfwscanf_internal directly from swscanf, without
duplicating the initialization code.  (Previously, they called their
v-counterparts, but that won't work if we want to control *both* C99
mode and ldbl-is-dbl mode using the flags argument to__vfscanf_internal.)
It's still a little awkward, especially for wide strfiles, but it's
much better than what we had.

Tested for powerpc and powerpc64le.
This commit is contained in:
Zack Weinberg
2018-03-07 14:31:58 -05:00
committed by Gabriel F. T. Gomes
parent 72b8692d7e
commit 349718d4d7
35 changed files with 3351 additions and 3128 deletions

View File

@ -704,6 +704,28 @@ extern off64_t _IO_seekpos_unlocked (FILE *, off64_t, int)
#endif /* _G_HAVE_MMAP */
/* Flags for __vfscanf_internal and __vfwscanf_internal.
SCANF_LDBL_IS_DBL indicates whether long double values are to be
handled as having the same format as double, in which case the flag
should be set to one, or as another format, otherwise.
SCANF_ISOC99_A, when set to one, indicates that the ISO C99 or POSIX
behavior of the scanf functions is to be used, i.e. automatic
allocation for input strings with %as, %aS and %a[, a GNU extension,
is disabled. This is the behavior that the __isoc99_scanf family of
functions use. When the flag is set to zero, automatic allocation is
enabled. */
#define SCANF_LDBL_IS_DBL 0x0001
#define SCANF_ISOC99_A 0x0002
extern int __vfscanf_internal (FILE *fp, const char *format, va_list argp,
unsigned int flags)
attribute_hidden;
extern int __vfwscanf_internal (FILE *fp, const wchar_t *format, va_list argp,
unsigned int flags)
attribute_hidden;
extern int _IO_vscanf (const char *, va_list) __THROW;
#ifdef _IO_MTSAFE_IO