Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!nbires!hao!gaia!jon From: jon@gaia.UUCP (Jonathan Corbet) Newsgroups: net.unix,net.micro.pc Subject: Bug in Microport stdio Message-ID: <123@gaia.UUCP> Date: Thu, 30-Oct-86 01:08:01 EST Article-I.D.: gaia.123 Posted: Thu Oct 30 01:08:01 1986 Date-Received: Fri, 31-Oct-86 03:35:29 EST Organization: Gaia Corp, Boulder, CO Lines: 53 Xref: mnetor net.unix:6080 net.micro.pc:7430 I have found what appears to be an obnoxious bug in the standard I/O library for Microport unix. Rather than let other folks out there track it down themselves, I thought I would pass it on: Essentially, the problem is this: when you fopen() a file for "r+" access, read from the file, then attempt to write, the data written gets lost. This happens even if you are careful to do a fseek() like the manual says. This breaks certain software, such as netnews. The solution I have found is to get the current position with ftell(), close and reopen the file, fseek() to the position of interest, then do the write. This little program demonstrates the bug. Simply compile (large OR small model), create a file "bug.test", and run it. You can then see that bug.test is not changed. # include main () /* * Demonstrate uPort stdio bug. */ { FILE *fp; int i; /* * Open up the file. */ if ((fp = fopen ("bug.test", "r+")) == NULL) { perror ("Can't open bug.test"); exit (1); } /* * Now we read a little ways into it, then write. Do the fseek, as required * by the manual entry. */ for (i = 0; i < 100; i++) fgetc (fp); if (fseek (fp, ftell (fp), 0)) { perror ("Fseek error"); exit (1); } fprintf (fp, "YOU SHOULD SEE THIS!"); fflush (fp); fclose (fp); } -- Jonathan Corbet {hao | nbires}!gaia!jon