Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Wed, 17 Aug 2022 20:31:10 -0400
From: Rich Felker <dalias@...c.org>
To: Florian Weimer <fweimer@...hat.com>
Cc: "Buchholz, Robert" <robert.buchholz@...e.com>,
	"musl@...ts.openwall.com" <musl@...ts.openwall.com>
Subject: Re: Bug: ftell() after fopen(..., "ab") returns 0 unless an
 explicit fseek() is used first

On Thu, Aug 11, 2022 at 01:36:33PM +0200, Florian Weimer wrote:
> * Robert Buchholz:
> 
> > On my Alpine/MUSL setup this prints "0 6" while on Ubuntu 22.04 with
> > glibc it prints "3 6" - which I'm assuming is the expected output.
> 
> Both behaviors are acceptable.  C11 (7.21.3p1) says this:
> 
> | If a file can support positioning requests (such as a disk file, as
> | opposed to a terminal), then a file position indicator associated with
> | the stream is positioned at the start (character number zero) of the
> | file, unless the file is opened with append mode in which case it is
> | implementation-defined whether the file position indicator is initially
> | positioned at the beginning or the end of the file.
> 
> musl is likely not the only libc with this type of behavior, given that
> it's explicitly allowed by the standard.

Indeed. We simply match the underlying fd behavior here because it's
the "default" behavior without incurring extra cost. Since
applications can't assume one behavior or the other, ones that care to
have the position start at the end have to do the fseeko to SEEK_END
themselves.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.