diff options
author | Zack Weinberg <zackw@panix.com> | 2018-03-07 14:32:01 -0500 |
---|---|---|
committer | Gabriel F. T. Gomes <gabriel@inconstante.eti.br> | 2018-12-05 18:15:42 -0200 |
commit | 698fb75b9ff5ae454a1344b5f9fafa0ca367c555 (patch) | |
tree | cf2b4ff04c4acd8af7bedacc0f42db69f6303f0d /libio | |
parent | Use SCANF_LDBL_IS_DBL instead of __ldbl_is_dbl. (diff) | |
download | glibc-698fb75b9ff5ae454a1344b5f9fafa0ca367c555.tar.gz glibc-698fb75b9ff5ae454a1344b5f9fafa0ca367c555.tar.bz2 glibc-698fb75b9ff5ae454a1344b5f9fafa0ca367c555.zip |
Add __v*printf_internal with flags arguments
There are a lot more printf variants than there are scanf variants,
and the code for setting up and tearing down their custom FILE
variants around the call to __vf(w)printf is more complicated and
variable. Therefore, I have added _internal versions of all the
v*printf variants, rather than introducing helper routines so that
they can all directly call __vf(w)printf_internal, as was done with
scanf.
As with the scanf changes, in this patch the _internal functions still
look at the environmental mode bits and all callers pass 0 for the
flags parameter.
Several of the affected public functions had _IO_ name aliases that
were not exported (but, in one case, appeared in libio.h anyway);
I was originally planning to leave them as aliases to avoid having
to touch internal callers, but it turns out ldbl_*_alias only work
for exported symbols, so they've all been removed instead. It also
turns out there were hardly any internal callers. _IO_vsprintf and
_IO_vfprintf *are* exported, so those two stick around.
Summary for the changes to each of the affected symbols:
_IO_vfprintf, _IO_vsprintf:
All internal calls removed, thus the internal declarations, as well
as uses of libc_hidden_proto and libc_hidden_def, were also removed.
The external symbol is now exposed via uses of ldbl_strong_alias
to __vfprintf_internal and __vsprintf_internal, respectively.
_IO_vasprintf, _IO_vdprintf, _IO_vsnprintf,
_IO_vfwprintf, _IO_vswprintf,
_IO_obstack_vprintf, _IO_obstack_printf:
All internal calls removed, thus declaration in internal headers
were also removed. They were never exported, so there are no
aliases tying them to the internal functions. I.e.: entirely gone.
__vsnprintf:
Internal calls were always preceded by macros such as
#define __vsnprintf _IO_vsnprintf, and
#define __vsnprintf vsnprintf
The macros were removed and their uses replaced with calls to the
new internal function __vsnprintf_internal. Since there were no
internal calls, the internal declaration was also removed. The
external symbol is preserved with ldbl_weak_alias to ___vsnprintf.
__vfwprintf:
All internal calls converted into calls to __vfwprintf_internal,
thus the internal declaration was removed. The function is now a
wrapper that calls __vfwprintf_internal. The external symbol is
preserved.
__vswprintf:
Similarly, but no external symbol.
__vasprintf, __vdprintf, __vfprintf, __vsprintf:
New internal wrappers. Not exported.
vasprintf, vdprintf, vfprintf, vsprintf, vsnprintf,
vfwprintf, vswprintf,
obstack_vprintf, obstack_printf:
These functions used to be aliases to the respective _IO_* function,
they are now aliases to their respective __* functions.
Tested for powerpc and powerpc64le.
Diffstat (limited to 'libio')
-rw-r--r-- | libio/fwprintf.c | 2 | ||||
-rw-r--r-- | libio/iolibio.h | 8 | ||||
-rw-r--r-- | libio/iovdprintf.c | 13 | ||||
-rw-r--r-- | libio/iovsprintf.c | 16 | ||||
-rw-r--r-- | libio/libio.h | 5 | ||||
-rw-r--r-- | libio/libioP.h | 47 | ||||
-rw-r--r-- | libio/obprintf.c | 19 | ||||
-rw-r--r-- | libio/swprintf.c | 2 | ||||
-rw-r--r-- | libio/vasprintf.c | 20 | ||||
-rw-r--r-- | libio/vsnprintf.c | 16 | ||||
-rw-r--r-- | libio/vswprintf.c | 16 | ||||
-rw-r--r-- | libio/vwprintf.c | 2 | ||||
-rw-r--r-- | libio/wprintf.c | 2 |
13 files changed, 114 insertions, 54 deletions
diff --git a/libio/fwprintf.c b/libio/fwprintf.c index fab63a8716..9903f1f342 100644 --- a/libio/fwprintf.c +++ b/libio/fwprintf.c @@ -30,7 +30,7 @@ __fwprintf (FILE *stream, const wchar_t *format, ...) int done; va_start (arg, format); - done = __vfwprintf (stream, format, arg); + done = __vfwprintf_internal (stream, format, arg, 0); va_end (arg); return done; diff --git a/libio/iolibio.h b/libio/iolibio.h index 6c94fe6d62..2642d71e4f 100644 --- a/libio/iolibio.h +++ b/libio/iolibio.h @@ -51,15 +51,7 @@ extern int _IO_sscanf (const char*, const char*, ...) __THROW; extern int _IO_sprintf (char *, const char*, ...) __THROW; extern int _IO_ungetc (int, FILE*) __THROW; extern int _IO_vsscanf (const char *, const char *, __gnuc_va_list) __THROW; -extern int _IO_vsprintf (char*, const char*, __gnuc_va_list) __THROW; -libc_hidden_proto (_IO_vsprintf) -extern int _IO_vswprintf (wchar_t*, size_t, const wchar_t*, __gnuc_va_list) - __THROW; -struct obstack; -extern int _IO_obstack_vprintf (struct obstack *, const char *, __gnuc_va_list) - __THROW; -extern int _IO_obstack_printf (struct obstack *, const char *, ...) __THROW; #define _IO_clearerr(FP) ((FP)->_flags &= ~(_IO_ERR_SEEN|_IO_EOF_SEEN)) #define _IO_fseek(__fp, __offset, __whence) \ (_IO_seekoff_unlocked (__fp, __offset, __whence, _IOS_INPUT|_IOS_OUTPUT) \ diff --git a/libio/iovdprintf.c b/libio/iovdprintf.c index 78a3a2bd15..1d2ed0f9e7 100644 --- a/libio/iovdprintf.c +++ b/libio/iovdprintf.c @@ -28,7 +28,8 @@ #include <stdio_ext.h> int -_IO_vdprintf (int d, const char *format, va_list arg) +__vdprintf_internal (int d, const char *format, va_list arg, + unsigned int mode_flags) { struct _IO_FILE_plus tmpfil; struct _IO_wide_data wd; @@ -50,7 +51,7 @@ _IO_vdprintf (int d, const char *format, va_list arg) _IO_mask_flags (&tmpfil.file, _IO_NO_READS, _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING); - done = _IO_vfprintf (&tmpfil.file, format, arg); + done = __vfprintf_internal (&tmpfil.file, format, arg, mode_flags); if (done != EOF && _IO_do_flush (&tmpfil.file) == EOF) done = EOF; @@ -59,4 +60,10 @@ _IO_vdprintf (int d, const char *format, va_list arg) return done; } -ldbl_weak_alias (_IO_vdprintf, vdprintf) + +int +__vdprintf (int d, const char *format, va_list arg) +{ + return __vdprintf_internal (d, format, arg, 0); +} +ldbl_weak_alias (__vdprintf, vdprintf) diff --git a/libio/iovsprintf.c b/libio/iovsprintf.c index 4def251701..3b1e8292b5 100644 --- a/libio/iovsprintf.c +++ b/libio/iovsprintf.c @@ -28,7 +28,8 @@ #include "strfile.h" int -__IO_vsprintf (char *string, const char *format, va_list args) +__vsprintf_internal (char *string, const char *format, va_list args, + unsigned int mode_flags) { _IO_strfile sf; int ret; @@ -39,11 +40,16 @@ __IO_vsprintf (char *string, const char *format, va_list args) _IO_no_init (&sf._sbf._f, _IO_USER_LOCK, -1, NULL, NULL); _IO_JUMPS (&sf._sbf) = &_IO_str_jumps; _IO_str_init_static_internal (&sf, string, -1, string); - ret = _IO_vfprintf (&sf._sbf._f, format, args); + ret = __vfprintf_internal (&sf._sbf._f, format, args, mode_flags); _IO_putc_unlocked ('\0', &sf._sbf._f); return ret; } -ldbl_hidden_def (__IO_vsprintf, _IO_vsprintf) -ldbl_strong_alias (__IO_vsprintf, _IO_vsprintf) -ldbl_weak_alias (__IO_vsprintf, vsprintf) +int +__vsprintf (char *string, const char *format, va_list args) +{ + return __vsprintf_internal (string, format, args, 0); +} + +ldbl_strong_alias (__vsprintf, _IO_vsprintf) +ldbl_weak_alias (__vsprintf, vsprintf) diff --git a/libio/libio.h b/libio/libio.h index 30cb7d784f..c188814ccc 100644 --- a/libio/libio.h +++ b/libio/libio.h @@ -255,8 +255,6 @@ extern int _IO_ftrylockfile (FILE *) __THROW; extern int _IO_vfscanf (FILE * __restrict, const char * __restrict, __gnuc_va_list, int *__restrict); -extern int _IO_vfprintf (FILE *__restrict, const char *__restrict, - __gnuc_va_list); extern __ssize_t _IO_padn (FILE *, int, __ssize_t); extern size_t _IO_sgetn (FILE *, void *, size_t); @@ -298,8 +296,6 @@ weak_extern (_IO_stdin_used); extern int _IO_vfwscanf (FILE * __restrict, const wchar_t * __restrict, __gnuc_va_list, int *__restrict); -extern int _IO_vfwprintf (FILE *__restrict, const wchar_t *__restrict, - __gnuc_va_list); extern __ssize_t _IO_wpadn (FILE *, wint_t, __ssize_t); extern void _IO_free_wbackup_area (FILE *) __THROW; @@ -319,7 +315,6 @@ libc_hidden_proto (_IO_free_wbackup_area) libc_hidden_proto (_IO_padn) libc_hidden_proto (_IO_putc) libc_hidden_proto (_IO_sgetn) -libc_hidden_proto (_IO_vfprintf) #ifdef _IO_MTSAFE_IO # undef _IO_peekc diff --git a/libio/libioP.h b/libio/libioP.h index 9e971cb96b..fe52ef1752 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -658,12 +658,49 @@ extern off64_t _IO_wstr_seekoff (FILE *, off64_t, int, int) extern wint_t _IO_wstr_pbackfail (FILE *, wint_t) __THROW; extern void _IO_wstr_finish (FILE *, int) __THROW; -extern int _IO_vasprintf (char **result_ptr, const char *format, - va_list args) __THROW; -extern int _IO_vdprintf (int d, const char *format, va_list arg); -extern int _IO_vsnprintf (char *string, size_t maxlen, - const char *format, va_list args) __THROW; +/* Internal versions of v*printf that take an additional flags + parameter. */ +extern int __vfprintf_internal (FILE *fp, const char *format, va_list ap, + unsigned int mode_flags) + attribute_hidden; +extern int __vfwprintf_internal (FILE *fp, const wchar_t *format, va_list ap, + unsigned int mode_flags) + attribute_hidden; + +extern int __vasprintf_internal (char **result_ptr, const char *format, + va_list ap, unsigned int mode_flags) + attribute_hidden; +extern int __vdprintf_internal (int d, const char *format, va_list ap, + unsigned int mode_flags) + attribute_hidden; +extern int __obstack_vprintf_internal (struct obstack *ob, const char *fmt, + va_list ap, unsigned int mode_flags) + attribute_hidden; + +extern int __vsprintf_internal (char *string, const char *format, va_list ap, + unsigned int mode_flags) + attribute_hidden; +extern int __vsnprintf_internal (char *string, size_t maxlen, + const char *format, va_list ap, + unsigned int mode_flags) + attribute_hidden; +extern int __vswprintf_internal (wchar_t *string, size_t maxlen, + const wchar_t *format, va_list ap, + unsigned int mode_flags) + attribute_hidden; + +/* Flags for __v*printf_internal. + + PRINTF_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. + PRINTF_FORTIFY, when set to one, indicates that fortification checks + are to be performed in input parameters. This is used by the + __*printf_chk functions, which are used when _FORTIFY_SOURCE is + defined to 1 or 2. Otherwise, such checks are ignored. */ +#define PRINTF_LDBL_IS_DBL 0x0001 +#define PRINTF_FORTIFY 0x0002 extern size_t _IO_getline (FILE *,char *, size_t, int, int); libc_hidden_proto (_IO_getline) diff --git a/libio/obprintf.c b/libio/obprintf.c index a74f9467a2..10a4b5c10c 100644 --- a/libio/obprintf.c +++ b/libio/obprintf.c @@ -117,7 +117,8 @@ const struct _IO_jump_t _IO_obstack_jumps libio_vtable attribute_hidden = int -_IO_obstack_vprintf (struct obstack *obstack, const char *format, va_list args) +__obstack_vprintf_internal (struct obstack *obstack, const char *format, + va_list args, unsigned int mode_flags) { struct obstack_FILE { @@ -164,7 +165,8 @@ _IO_obstack_vprintf (struct obstack *obstack, const char *format, va_list args) new_f.ofile.obstack = obstack; - result = _IO_vfprintf (&new_f.ofile.file.file, format, args); + result = __vfprintf_internal (&new_f.ofile.file.file, format, args, + mode_flags); /* Shrink the buffer to the space we really currently need. */ obstack_blank_fast (obstack, (new_f.ofile.file.file._IO_write_ptr @@ -172,17 +174,22 @@ _IO_obstack_vprintf (struct obstack *obstack, const char *format, va_list args) return result; } -ldbl_weak_alias (_IO_obstack_vprintf, obstack_vprintf) +int +__obstack_vprintf (struct obstack *obstack, const char *format, va_list ap) +{ + return __obstack_vprintf_internal (obstack, format, ap, 0); +} +ldbl_weak_alias (__obstack_vprintf, obstack_vprintf) int -_IO_obstack_printf (struct obstack *obstack, const char *format, ...) +__obstack_printf (struct obstack *obstack, const char *format, ...) { int result; va_list ap; va_start (ap, format); - result = _IO_obstack_vprintf (obstack, format, ap); + result = __obstack_vprintf_internal (obstack, format, ap, 0); va_end (ap); return result; } -ldbl_weak_alias (_IO_obstack_printf, obstack_printf) +ldbl_weak_alias (__obstack_printf, obstack_printf) diff --git a/libio/swprintf.c b/libio/swprintf.c index 10f722d035..19b3f33198 100644 --- a/libio/swprintf.c +++ b/libio/swprintf.c @@ -28,7 +28,7 @@ __swprintf (wchar_t *s, size_t n, const wchar_t *format, ...) int done; va_start (arg, format); - done = __vswprintf (s, n, format, arg); + done = __vswprintf_internal (s, n, format, arg, 0); va_end (arg); return done; diff --git a/libio/vasprintf.c b/libio/vasprintf.c index 6c35d2b108..fabd84f403 100644 --- a/libio/vasprintf.c +++ b/libio/vasprintf.c @@ -24,15 +24,13 @@ This exception applies to code released by its copyright holders in files containing the exception. */ -#include <malloc.h> #include <string.h> -#include "libioP.h" -#include "stdio.h" -#include <stdio_ext.h> -#include "strfile.h" +#include <stdlib.h> +#include <strfile.h> int -_IO_vasprintf (char **result_ptr, const char *format, va_list args) +__vasprintf_internal (char **result_ptr, const char *format, va_list args, + unsigned int mode_flags) { /* Initial size of the buffer to be used. Will be doubled each time an overflow occurs. */ @@ -56,7 +54,7 @@ _IO_vasprintf (char **result_ptr, const char *format, va_list args) sf._sbf._f._flags &= ~_IO_USER_BUF; sf._s._allocate_buffer_unused = (_IO_alloc_type) malloc; sf._s._free_buffer_unused = (_IO_free_type) free; - ret = _IO_vfprintf (&sf._sbf._f, format, args); + ret = __vfprintf_internal (&sf._sbf._f, format, args, mode_flags); if (ret < 0) { free (sf._sbf._f._IO_buf_base); @@ -85,4 +83,10 @@ _IO_vasprintf (char **result_ptr, const char *format, va_list args) (*result_ptr)[needed - 1] = '\0'; return ret; } -ldbl_weak_alias (_IO_vasprintf, vasprintf) + +int +__vasprintf (char **result_ptr, const char *format, va_list args) +{ + return __vasprintf_internal (result_ptr, format, args, 0); +} +ldbl_weak_alias (__vasprintf, vasprintf) diff --git a/libio/vsnprintf.c b/libio/vsnprintf.c index 39b5500528..35b267abf8 100644 --- a/libio/vsnprintf.c +++ b/libio/vsnprintf.c @@ -90,8 +90,8 @@ const struct _IO_jump_t _IO_strn_jumps libio_vtable attribute_hidden = int -_IO_vsnprintf (char *string, size_t maxlen, const char *format, - va_list args) +__vsnprintf_internal (char *string, size_t maxlen, const char *format, + va_list args, unsigned int mode_flags) { _IO_strnfile sf; int ret; @@ -111,11 +111,17 @@ _IO_vsnprintf (char *string, size_t maxlen, const char *format, _IO_JUMPS (&sf.f._sbf) = &_IO_strn_jumps; string[0] = '\0'; _IO_str_init_static_internal (&sf.f, string, maxlen - 1, string); - ret = _IO_vfprintf (&sf.f._sbf._f, format, args); + ret = __vfprintf_internal (&sf.f._sbf._f, format, args, mode_flags); if (sf.f._sbf._f._IO_buf_base != sf.overflow_buf) *sf.f._sbf._f._IO_write_ptr = '\0'; return ret; } -ldbl_weak_alias (_IO_vsnprintf, __vsnprintf) -ldbl_weak_alias (_IO_vsnprintf, vsnprintf) + +int +___vsnprintf (char *string, size_t maxlen, const char *format, va_list args) +{ + return __vsnprintf_internal (string, maxlen, format, args, 0); +} +ldbl_weak_alias (___vsnprintf, __vsnprintf) +ldbl_weak_alias (___vsnprintf, vsnprintf) diff --git a/libio/vswprintf.c b/libio/vswprintf.c index bcc473d115..e415e39fc9 100644 --- a/libio/vswprintf.c +++ b/libio/vswprintf.c @@ -89,8 +89,8 @@ const struct _IO_jump_t _IO_wstrn_jumps libio_vtable attribute_hidden = int -_IO_vswprintf (wchar_t *string, size_t maxlen, const wchar_t *format, - va_list args) +__vswprintf_internal (wchar_t *string, size_t maxlen, const wchar_t *format, + va_list args, unsigned int mode_flags) { _IO_wstrnfile sf; int ret; @@ -108,7 +108,7 @@ _IO_vswprintf (wchar_t *string, size_t maxlen, const wchar_t *format, _IO_fwide (&sf.f._sbf._f, 1); string[0] = L'\0'; _IO_wstr_init_static (&sf.f._sbf._f, string, maxlen - 1, string); - ret = _IO_vfwprintf ((FILE *) &sf.f._sbf, format, args); + ret = __vfwprintf_internal ((FILE *) &sf.f._sbf, format, args, mode_flags); if (sf.f._sbf._f._wide_data->_IO_buf_base == sf.overflow_buf) /* ISO C99 requires swprintf/vswprintf to return an error if the @@ -120,5 +120,11 @@ _IO_vswprintf (wchar_t *string, size_t maxlen, const wchar_t *format, return ret; } -weak_alias (_IO_vswprintf, __vswprintf) -ldbl_weak_alias (_IO_vswprintf, vswprintf) + +int +__vswprintf (wchar_t *string, size_t maxlen, const wchar_t *format, + va_list args) +{ + return __vswprintf_internal (string, maxlen, format, args, 0); +} +ldbl_weak_alias (__vswprintf, vswprintf) diff --git a/libio/vwprintf.c b/libio/vwprintf.c index 72ebfec92d..e8a529afff 100644 --- a/libio/vwprintf.c +++ b/libio/vwprintf.c @@ -25,6 +25,6 @@ int __vwprintf (const wchar_t *format, __gnuc_va_list arg) { - return __vfwprintf (stdout, format, arg); + return __vfwprintf_internal (stdout, format, arg, 0); } ldbl_strong_alias (__vwprintf, vwprintf) diff --git a/libio/wprintf.c b/libio/wprintf.c index 5945f651fc..361cd40a1b 100644 --- a/libio/wprintf.c +++ b/libio/wprintf.c @@ -29,7 +29,7 @@ __wprintf (const wchar_t *format, ...) int done; va_start (arg, format); - done = __vfwprintf (stdout, format, arg); + done = __vfwprintf_internal (stdout, format, arg, 0); va_end (arg); return done; |