Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 05 Jan 2001 17:34:02 GMT
From:      "Joshua Rosen" <rozzin@geekspace.com>
To:        Alfred Perlstein <bright@wintelcom.net>
Cc:        Chris Williams <psion@geekspace.com>, freebsd-hackers@FreeBSD.ORG, rozzin@geekspace.com
Subject:   Re: Strange fwrite() behavior in a+ mode
Message-ID:  <20010105173402.3537.qmail@jello.geekspace.com>
In-Reply-To: <20010104171504.A15744@fw.wintelcom.net>
References:  <3A551ABD.DBC9BD5C@geekspace.com> <20010104171504.A15744@fw.wintelcom.net>

next in thread | previous in thread | raw e-mail | index | archive | help

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010105173402.3537.qmail>