[PATCH 1/2] Move offset to end of file when fdopen is in "a" mode (#16532)
Rich Felker
dalias@aerifal.cx
Tue Feb 11 09:55:00 GMT 2014
On Tue, Feb 11, 2014 at 02:08:00PM +0530, Siddhesh Poyarekar wrote:
> Hi,
>
> Unlike fopen, fdopen fails to move the offset in the file descriptor
> to the end of file when the file is opened in append mode (a). This
> results in ftell{,o} incorrectly assuming that the current offset is
> at the beginning of file and returns an incorrect result. This was
> exposed due to commit adb26fae.
Are you sure this fixes the issue? I think there are still cases where
the wrong offset might be seen. For instance it's legal to call lseek
on the fd after calling fdopen (the FILE is not the "active handle"
until you read/write with it) and then ftell could still report the
wrong result.
We had a similar bug in musl (but not the same; it manifested in more
cases than the glibc one) and I fixed it by doing the repositioning at
ftello time when the stream is append-mode and there's unwritten
buffered data:
http://git.musl-libc.org/cgit/musl/commit/?id=3af2edee150484940916eba1984f78c3b965dd05
Rich
More information about the Libc-alpha
mailing list