summaryrefslogtreecommitdiff
path: root/libc/libio/fileops.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/libio/fileops.c')
-rw-r--r--libc/libio/fileops.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/libc/libio/fileops.c b/libc/libio/fileops.c
index 9b03a9c55..1f7356540 100644
--- a/libc/libio/fileops.c
+++ b/libc/libio/fileops.c
@@ -161,19 +161,27 @@ 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 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;
+ }
else
write_status = 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