diff options
Diffstat (limited to 'libio/fileops.c')
-rw-r--r-- | libio/fileops.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/libio/fileops.c b/libio/fileops.c index 1e7ef0754c..adf4cfaea9 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -160,19 +160,25 @@ int _IO_new_file_close_it (fp) _IO_FILE *fp; { - int write_status, close_status; if (!_IO_file_is_open (fp)) return EOF; - if ((fp->_flags & _IO_NO_WRITES) == 0 - && (fp->_flags & _IO_CURRENTLY_PUTTING) != 0) + int write_status; + if (_IO_in_put_mode (fp)) write_status = _IO_do_flush (fp); - else - write_status = 0; + else if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL + && !_IO_in_backup (fp)) + { + off64_t o = _IO_SEEKOFF (fp, 0, _IO_seek_cur, 0); + if (o == WEOF) + write_status = EOF; + else + write_status = _IO_SYSSEEK (fp, o, SEEK_SET) < 0 ? EOF : 0; + } INTUSE(_IO_unsave_markers) (fp); - close_status = _IO_SYSCLOSE (fp); + int close_status = _IO_SYSCLOSE (fp); /* Free buffer. */ #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T |