[PATCH v2] Fix ftell with fdopen for all cases and fopen with a+ mode (#16532)

Rich Felker dalias@aerifal.cx
Tue Feb 18 16:27:00 GMT 2014


On Tue, Feb 18, 2014 at 09:36:50PM +0530, Siddhesh Poyarekar wrote:
> open/attached and the buffer not yet flushed.  Subsequent queries
> should always be correct since applications are required to flush or
> seek to the desired position when switching between reading or
> writing, both of which sync up the offset.

Having the flush/seek sync the offset is not valid, since it's
permissible to switch to using a different active handle (e.g. the
underlying fd or a copy of the FILE in a forked child) at this point
and adjust the offset before switching back to this FILE. Instead,
explicit flush/seek operations need to reset the offset status to
"unknown" so that future ftell operations will query it again like
they did the first time. Implicit flush from the buffer filling up
does not need to do this.

Rich



More information about the Libc-alpha mailing list