Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!tektronix!ogcvax!omsvax!hplabs!sri-unix!jeff@aids-unix From: jeff%aids-unix@sri-unix.UUCP Newsgroups: net.unix-wizards Subject: Re: r+ on fopen. Message-ID: <11831@sri-arpa.UUCP> Date: Mon, 19-Sep-83 15:02:22 EDT Article-I.D.: sri-arpa.11831 Posted: Mon Sep 19 15:02:22 1983 Date-Received: Sat, 24-Sep-83 00:53:23 EDT Lines: 26 From: Jeff Dean No, I am not the anonymous hacker, but there really is a problem with read/write files under 4.1 bsd. To see the problem, fopen a file in "r+", fgets a line, fseek to an odd location, and then fwrite something there (and then fclose the file). Nothing has been written! Repeat this, fseeking to an even location, and now the fwrite works correctly. According to the manual, an fseek is necessary to switch between read and write. However, there is a problem with fseek which causes it to incorrectly switch modes. Under certain conditions, an fseek to an odd location causes a seek to ( location - 1 ), followed by a getc (!). Unfortunately, getc puts the buffer back into read mode, causing fseek to exit with the buffer still in read mode. Placing an fflush in the program will not solve the problem. fseek is leaving the buffer in read mode; fflush has no effect on a buffer in read mode. An obvious solution to this problem is to simply remove the offending code (all code dealing with the variable "resync"). Is there some reason that this "resync" code is there? (a PDP11-ism ?) jd