Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site well.UUCP Path: utzoo!linus!decvax!ucbvax!ucdavis!lll-crg!well!fnf From: fnf@well.UUCP (Fred Fish) Newsgroups: net.micro.amiga Subject: bug in Lattice fopen() Message-ID: <430@well.UUCP> Date: Mon, 6-Jan-86 00:26:09 EST Article-I.D.: well.430 Posted: Mon Jan 6 00:26:09 1986 Date-Received: Tue, 7-Jan-86 06:24:01 EST Organization: Whole Earth Lectronic Link, Sausalito, CA Lines: 31 Keywords: append mode 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 ===============================================================================