From fa3cd24827d34a49e0a3a5cac56abbf8df74d8ac Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Tue, 4 Mar 2014 12:23:27 +0530 Subject: Use cached offset in ftell when reliable The cached offset is reliable to use in ftell when the stream handle is active. We can consider a stream as being active when there is unflushed data. However, even in this case, we can use the cached offset only when the stream is not being written to in a+ mode, because this case may have unflushed data and a stale offset; the previous read could have sent it off somewhere other than the end of the file. There were a couple of adjustments necessary to get this to work. Firstly, fdopen now ceases to use _IO_attach_fd because it sets the offset cache to the current file position. This is not correct because there could be changes to the file descriptor before the stream handle is activated, which would not get reflected. A similar offset caching action is done in _IO_fwide, claiming that wide streams have 'problems' with the file offsets. There don't seem to be any obvious problems with not having the offset cache available, other than that it will have to be queried in a subsequent read/write/seek. I have removed this as well. The testsuite passes successfully with these changes on x86_64. --- libio/iofwide.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'libio/iofwide.c') diff --git a/libio/iofwide.c b/libio/iofwide.c index 5cff6325f1..64187e401b 100644 --- a/libio/iofwide.c +++ b/libio/iofwide.c @@ -199,12 +199,6 @@ _IO_fwide (fp, mode) /* From now on use the wide character callback functions. */ ((struct _IO_FILE_plus *) fp)->vtable = fp->_wide_data->_wide_vtable; - - /* One last twist: we get the current stream position. The wide - char streams have much more problems with not knowing the - current position and so we should disable the optimization - which allows the functions without knowing the position. */ - fp->_offset = _IO_SYSSEEK (fp, 0, _IO_seek_cur); } /* Set the mode now. */ -- cgit 1.4.1