Path: utzoo!attcan!uunet!samsung!olivea!tymix!cirrusl!ss108!dhesi From: dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) Newsgroups: comp.lang.c Subject: Re: problem with fread/fwrite Keywords: fread, fwrite, file pointers Message-ID: <2677@cirrusl.UUCP> Date: 12 Nov 90 04:52:11 GMT References: <402@bally.Bally.COM> <14384@smoke.brl.mil> <13992@ulysses.att.com> Sender: news@cirrusl.UUCP Organization: Cirrus Logic Inc. Lines: 31 In <13992@ulysses.att.com> kpv@ulysses.att.com (Phong Vo[drew]) writes: The standard, in this case, basically just documents the behavior of stdio without considering that this is a bad design that arose from a bad implementation. It is ugly to have to call fseek before switching modes. I believe the requirement to call fseek (etc.) when switching arises out of the need to make stdio fast. Due to buffering, alternating reads and writes can confuse each other. The only way the stdio library could automatically protect you against this would be for it to explicitly test for internal state before every read and write. E.g., within fread, we sould have: if (my_state == DOING_WRITE) { .. resync buffer .. my_state = DOING_READ; .. rest of fread .. } I suppose we should consider ourselves lucky we are even allowed to do both reads and writes on the same data stream: I had the blues because I had no shoes Until upon the street I met a man whose feet were stuck in Pascal. -- Rahul Dhesi UUCP: oliveb!cirrusl!dhesi