fnf@well.UUCP (Fred Fish) (01/06/86)
I just got bit by a bug in the Lattice C runtime environment function
"fopen". When the second argument to fopen is either "a" or "a+",
the specified file is always truncated, regardless of whether or not
it already exists. A simple workaround for cases where only one
process will be writing to the file is to replace:
if ((fp = fopen (filename, "a+")) == NULL)
perror ("can't open file!");
with
if ((fp = fopen (filename, "r+")) == NULL)
if ((fp = fopen (filename "w+")) == NULL)
perror ("can't open file!");
fseek (fp, 0L, 2);
And occurances of
fwrite (ptr, size, nitems, fp);
with
fseek (fp, 0L, 2);
fwrite (ptr, size, nitems, fp);
-Fred
--
===============================================================================
Fred Fish (415) 644-1230 ext 242 ucbvax!unisoft!fnf well!fnf
===============================================================================