From owner-freebsd-hackers Fri Jan 5 9:31:15 2001 From owner-freebsd-hackers@FreeBSD.ORG Fri Jan 5 09:31:12 2001 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from jello.geekspace.com (jello.geekspace.com [63.175.99.14]) by hub.freebsd.org (Postfix) with SMTP id E623337B400 for ; Fri, 5 Jan 2001 09:31:11 -0800 (PST) Received: (qmail 3538 invoked by uid 1002); 5 Jan 2001 17:34:02 -0000 Message-ID: <20010105173402.3537.qmail@jello.geekspace.com> References: <3A551ABD.DBC9BD5C@geekspace.com> <20010104171504.A15744@fw.wintelcom.net> In-Reply-To: <20010104171504.A15744@fw.wintelcom.net> From: "Joshua Rosen" To: Alfred Perlstein Cc: Chris Williams , freebsd-hackers@FreeBSD.ORG, rozzin@geekspace.com Subject: Re: Strange fwrite() behavior in a+ mode Date: Fri, 05 Jan 2001 17:34:02 GMT Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: rozzin@jello.geekspace.com Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message