From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 13701 invoked from network); 18 Aug 2022 00:31:27 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 18 Aug 2022 00:31:27 -0000 Received: (qmail 31940 invoked by uid 550); 18 Aug 2022 00:31:24 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 31920 invoked from network); 18 Aug 2022 00:31:23 -0000 Date: Wed, 17 Aug 2022 20:31:10 -0400 From: Rich Felker To: Florian Weimer Cc: "Buchholz, Robert" , "musl@lists.openwall.com" Message-ID: <20220818003110.GF7074@brightrain.aerifal.cx> References: <87tu6jt3jy.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87tu6jt3jy.fsf@oldenburg.str.redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] 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