Bug in Microport stdio

Jonathan Corbet jon at gaia.UUCP
Thu Oct 30 16:08:01 AEST 1986


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 <stdio.h>

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



More information about the Comp.unix mailing list