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

libio: use stdout in puts and putchar, etc [BZ #24051].

GLIBC explicitly allows one to assign a new FILE pointer to stdout and
other standard streams.  printf and wprintf were honouring assignment to
stdout and using the new value, but puts, putchar, and wide char variants
did not.

The stdout part is fixed here.  The stdin part will be fixed in a followup.
This commit is contained in:
Paul Pluzhnikov
2018-12-31 19:14:28 -08:00
parent 583dd860d5
commit 5f10701fdc
10 changed files with 119 additions and 25 deletions

View File

@ -33,15 +33,15 @@ _IO_puts (const char *str)
{
int result = EOF;
size_t len = strlen (str);
_IO_acquire_lock (_IO_stdout);
_IO_acquire_lock (stdout);
if ((_IO_vtable_offset (_IO_stdout) != 0
|| _IO_fwide (_IO_stdout, -1) == -1)
&& _IO_sputn (_IO_stdout, str, len) == len
&& _IO_putc_unlocked ('\n', _IO_stdout) != EOF)
if ((_IO_vtable_offset (stdout) != 0
|| _IO_fwide (stdout, -1) == -1)
&& _IO_sputn (stdout, str, len) == len
&& _IO_putc_unlocked ('\n', stdout) != EOF)
result = MIN (INT_MAX, len + 1);
_IO_release_lock (_IO_stdout);
_IO_release_lock (stdout);
return result;
}