mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-07 06:43:00 +03:00
Fix fflush after ungetc on input file (bug 5994)
As discussed in bug 5994 (plus duplicates), POSIX requires fflush after ungetc to discard pushed-back characters but preserve the file position indicator. For this purpose, each ungetc decrements the file position indicator by 1; it is unspecified after ungetc at the start of the file, and after ungetwc, so no special handling is needed for either of those cases. This is fixed with appropriate logic in _IO_new_file_sync. I haven't made any attempt to test or change things in this area for the "old" functions; the case of files using mmap is addressed in a subsequent patch (and there seem to be no problems in this area with files opened with fmemopen). Tested for x86_64.
This commit is contained in:
@@ -800,6 +800,11 @@ _IO_new_file_sync (FILE *fp)
|
||||
if (fp->_IO_write_ptr > fp->_IO_write_base)
|
||||
if (_IO_do_flush(fp)) return EOF;
|
||||
delta = fp->_IO_read_ptr - fp->_IO_read_end;
|
||||
if (_IO_in_backup (fp))
|
||||
{
|
||||
_IO_switch_to_main_get_area (fp);
|
||||
delta += fp->_IO_read_ptr - fp->_IO_read_end;
|
||||
}
|
||||
if (delta != 0)
|
||||
{
|
||||
off64_t new_pos = _IO_SYSSEEK (fp, delta, 1);
|
||||
|
Reference in New Issue
Block a user