Date: Fri, 5 Jan 2001 09:47:21 -0800 From: Alfred Perlstein <bright@wintelcom.net> To: Joshua Rosen <rozzin@geekspace.com> Cc: Chris Williams <psion@geekspace.com>, freebsd-hackers@FreeBSD.ORG Subject: Re: Strange fwrite() behavior in a+ mode Message-ID: <20010105094721.B15744@fw.wintelcom.net> In-Reply-To: <20010105173402.3537.qmail@jello.geekspace.com>; from rozzin@geekspace.com on Fri, Jan 05, 2001 at 05:34:02PM %2B0000 References: <3A551ABD.DBC9BD5C@geekspace.com> <20010104171504.A15744@fw.wintelcom.net> <20010105173402.3537.qmail@jello.geekspace.com>
next in thread | previous in thread | raw e-mail | index | archive | help
* Joshua Rosen <rozzin@geekspace.com> [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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010105094721.B15744>