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 at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Mon, 10 Mar 2014 11:37:13 -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>
On Mon, Mar 10, 2014 at 05:53:06PM +0530, Siddhesh Poyarekar wrote:
> Hi,
>
> 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.
>
> For a and a+ mode files in read mode, rewinding the stream should
> result in ftell returning 0 as the offset, but without caching, it
> just assumes that the file offset is the end of file (as opposed to
> SEEK_CUR, since rewind correctly sets it). 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 best way to fix this would be to avoid caching the offset before
> the file handle is active. With this change, the only time the offset
> cache is not reliable is when the file is writing in any of the append
> modes.
I'm confused. I thought we discussed before that caching the offset is
_always_ invalid when the file handle is not active. This is not
specific to append mode.
Rich