This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Never cache offset when the stream handle is not active (BZ #16680)
- From: Rich Felker <dalias at aerifal dot cx>
- To: Siddhesh Poyarekar <siddhesh dot poyarekar at gmail dot com>
- Cc: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Date: Mon, 10 Mar 2014 23:15:48 -0400
- Subject: Re: [PATCH] Never cache offset when the stream handle is not active (BZ #16680)
- Authentication-results: sourceware.org; auth=none
- References: <20140310122306 dot GF1656 at spoyarek dot pnq dot redhat dot com> <20140310153713 dot GG184 at brightrain dot aerifal dot cx> <20140310154204 dot GH1656 at spoyarek dot pnq dot redhat dot com> <20140310183459 dot GI184 at brightrain dot aerifal dot cx> <20140311003935 dot GJ1656 at spoyarek dot pnq dot redhat dot com> <20140311023921 dot GL184 at brightrain dot aerifal dot cx> <CAAHN_R33WB8rFD_Lq+vtk50oNsa16oDC+jywXn5G1qS4s2q3rw at mail dot gmail dot com>
On Tue, Mar 11, 2014 at 08:24:26AM +0530, Siddhesh Poyarekar wrote:
> On Tuesday, 11 March 2014, Rich Felker <dalias@aerifal.cx> wrote:
>
> > On Tue, Mar 11, 2014 at 06:09:35AM +0530, Siddhesh Poyarekar wrote:
> > > On Mon, Mar 10, 2014 at 02:34:59PM -0400, Rich Felker wrote:
> > > > Caching the offset is valid when writing in append mode. The one case
> > > > that's special for append mode is that, even once the handle is
> > > > active, you can't save the resulting offset at the time of seek/rewind
> > > > and use it for ftell during subsequent writing. This is because the
> > > > (first) write after seeking could change the current offset. One easy
> > > > way to deal with this is to treat seek/rewind as deactivating the
> > > > handle when the stream is in append mode, but more fine-grained
> > > > solutions are possible too.
> > >
> > > Treating seek/rewind as deactivating the handle won't help for append
> > > mode because we want to simulate the file position as being the end of
> > > file regardless of the file position when the handle is inactive, but
> >
> > Why do you want to do this? It's wrong. If the handle is inactive, the
>
> only way you can get the position is by calling lseek(fd,0,SEEK_CUR).
>
> This is because operations on another handle could have changed the
> > position without stdio's knowledge.
> >
>
> Because that would give an inconsistent result. Initial position for append
> mode files is implementation defined and glibc has set it as end of file in
> the past. Changing that would be a breakage, wouldn't it?
Then fopen needs to physically seek to the end of the file with lseek
when append mode is requested. Faking the position is non-conforming
because it does not respect the rules for active handles.
Rich