diff options
author | Siddhesh Poyarekar <siddhesh@redhat.com> | 2014-03-11 17:04:49 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@redhat.com> | 2014-03-17 21:23:56 +0530 |
commit | ea33158c96c53a64402a772186956c1f5cb556ae (patch) | |
tree | 038673c1ab8849eb3311aa1f8d66c23ee654cf42 /NEWS | |
parent | b1dbb426e164ad1236c2c76268e03fec5c7a7bbe (diff) | |
download | glibc-ea33158c96c53a64402a772186956c1f5cb556ae.tar.gz glibc-ea33158c96c53a64402a772186956c1f5cb556ae.tar.xz glibc-ea33158c96c53a64402a772186956c1f5cb556ae.zip |
Fix offset caching for streams and use it for ftell (BZ #16680)
The ftell implementation was made conservative to ensure that incorrectly cached offsets never affect it. However, this causes problems for append mode when a file stream is rewound. Additionally, the 'clever' trick of using stat to get position for append mode files caused more problems than it solved and broke old behavior. I have described the various problems that it caused and then finally the solution. For a and a+ mode files, rewinding the stream should result in ftell returning 0 as the offset, but the stat() trick caused it to (incorrectly) always return the end of file. Now I couldn't find anything in POSIX that specifies the stream position after rewind() for a file opened in 'a' mode, but for 'a+' mode it should be set to 0. For 'a' mode too, it probably makes sense to keep it set to 0 in the interest of retaining old behavior. The initial file position for append mode files is implementation defined, so the implementation could either retain the current file position or move the position to the end of file. The earlier ftell implementation would move the offset to end of file for append-only mode, but retain the old offset for a+ mode. It would also cache the offset (this detail is important). My patch broke this and would set the initial position to end of file for both append modes, thus breaking old behavior. I was ignorant enough to write an incorrect test case for it too. The Change: I have now brought back the behavior of seeking to end of file for append-only streams, but with a slight difference. I don't cache the offset though, since we would want ftell to query the current file position through lseek while the stream is not active. Since the offset is moved to the end of file, we can rely on the file position reported by lseek and we don't need to resort to the stat() nonsense. Finally, the cache is always reliable, except when there are unflished writes in an append mode stream (i.e. both a and a+). In the latter case, it is safe to just do an lseek to SEEK_END. The value can be safely cached too, since the file handle is already active at this point. Incidentally, this is the only state change we affect in the file handle (apart from taking locks of course). I have also updated the test case to correct my impression of the initial file position for a+ streams to the initial behavior. I have verified that this does not break any existing tests in the testsuite and also passes with the new tests.
Diffstat (limited to 'NEWS')
-rw-r--r-- | NEWS | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/NEWS b/NEWS index c69d40a7ee..df5507afcb 100644 --- a/NEWS +++ b/NEWS @@ -10,8 +10,8 @@ Version 2.20 * The following bugs are resolved with this release: 15347, 15804, 15894, 16447, 16532, 16545, 16574, 16600, 16609, 16610, - 16611, 16613, 16623, 16632, 16639, 16642, 16670, 16674, 16677, 16683, - 16689, 16695, 16701, 16706, 16707. + 16611, 16613, 16623, 16632, 16639, 16642, 16670, 16674, 16677, 16680, + 16683, 16689, 16695, 16701, 16706, 16707. * Running the testsuite no longer terminates as soon as a test fails. Instead, a file tests.sum (xtests.sum from "make xcheck") is generated, |