[comp.lang.c] TC bugs

ydist@unix.cis.pitt.edu (Yijun Ding) (09/05/90)

I recently got the patch files for TC 2.0 from simtel20. 
This cleard some entries from my TC-bug-list.  The following
program demonstrates other two possible bugs.  The first is
definitely a bug.  When compiled on unix system, it print 3.14e...
instead of 3.1e...    The second, I am not sure.  The "a+" format
does not allow write to the beginning of files in TC.  On unix,
the printout is "isis is a ..." instead of "This is a..." on TC.
Any comments?

#include <stdio.h>
#include <math.h>

FILE *fi;
char buf[]="This is a test.\n";

main()
{
	/* e-format precision incorrect */
	printf("%5.2e\n", 3.141596);

	/* a+ can't write over */
	fi = fopen("tmp.doc", "a+");
	fwrite(buf, sizeof(buf), 1, fi);
	fseek(fi, 0L, 0);
	fwrite(buf+2, 2, 1, fi);
	fseek(fi, 0L, 0);
	fread(buf, sizeof(buf), 1, fi);
	printf(buf);
	getchar();
}

karl@haddock.ima.isc.com (Karl Heuer) (09/06/90)

In article <35025@unix.cis.pitt.edu> ydist@unix.cis.pitt.edu (Yijun Ding) writes:
>The second, I am not sure.  The "a+" format does not allow write to the
>beginning of files in TC.  On unix, the printout is "isis is a ..." instead
>of "This is a..." on TC.

TC is correct, some versions of Unix have it wrong (when measured against the
ANSI C Standard).  "Opening a file with append mode causes all subsequent
writes to be forced to the then current end-of-file, regardless of intervening
calls to fseek()."  [4.9.5.3]

Karl W. Z. Heuer (karl@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint