From owner-freebsd-hackers Fri Jan 5 9:47:25 2001 From owner-freebsd-hackers@FreeBSD.ORG Fri Jan 5 09:47:23 2001 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id D9D7F37B402 for ; Fri, 5 Jan 2001 09:47:22 -0800 (PST) Received: (from bright@localhost) by fw.wintelcom.net (8.10.0/8.10.0) id f05HlLS10067; Fri, 5 Jan 2001 09:47:21 -0800 (PST) Date: Fri, 5 Jan 2001 09:47:21 -0800 From: Alfred Perlstein To: Joshua Rosen Cc: Chris Williams , freebsd-hackers@FreeBSD.ORG Subject: Re: Strange fwrite() behavior in a+ mode Message-ID: <20010105094721.B15744@fw.wintelcom.net> References: <3A551ABD.DBC9BD5C@geekspace.com> <20010104171504.A15744@fw.wintelcom.net> <20010105173402.3537.qmail@jello.geekspace.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010105173402.3537.qmail@jello.geekspace.com>; from rozzin@geekspace.com on Fri, Jan 05, 2001 at 05:34:02PM +0000 Sender: bright@fw.wintelcom.net Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG * Joshua Rosen [010105 09:31] wrote: > > Alfred Perlstein writes: > > > So in Linux, if you have a "a+" file, you can > > 1) seek somewhere (mid file) > > 2) read some data (not until EOF) > > 3) after the read you are at EOF again? > > > > this doesn't sound really intuative. > > No, it doesn't sound intuitive; luckily, that isn't what happens;) > The issue concerns where the position is after a write (and where ftell > reports it as being). > > Under glibc on Linux, you can: > 1) fseek somewhere (non-EOF) > 2) fwrite some data > 3) after the *write*, you are at EOF again (ftell reports this, and any > attempted fread, at this point, will hit EOF. any fseek, after a write, > using SEEK_CUR will seek relative to EOF, also) > > I guess that the idea is, `bytes are read/written starting at the current > position in the file', and, in order to do this in a system which always > writes after EOF in append-mode, the current position must be changed > before writing.... > > my findings, under FreeBSD 4.2-STABLE, are > 1) fseek somewhere (non-EOF, say 4 in a 50-byte-long file) > 2) fwrite some data (say 3 bytes) > 3) after the fwrite, ftell will report N + the last value pass'd to fseek > (using our example numbers: 7), and fseek with SEEK_CUR will seek relative > to that point, but fread will immediately hit EOF, and a ftell (or feof) > after an attempted read will indicate that the position *is* EOF. > > Chris' findings (I believe) are that, under FreeBSD 4.2-STABLE, if you use > fread before fwrite (say, step `1.1'), it acts just like it does with > glibc/Linux. Can you do a bit more research and let me know if this happens when using open/read/write/lseek as well? -- -Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org] "I have the heart of a child; I keep it in a jar on my desk." To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message