Mail Archives: djgpp-workers/1999/04/06/05:24:50
Hi, all.
The following program does not do what I (and Autoconf) expected:
#include <stdio.h>
int main(void)
{
FILE *fpw, *fpr;
char array[7];
fpw = fopen("conftes0", "w");
fwrite("FOOBAR", 1, 7, fpw);
fflush(fpw);
/*fsync(fileno(fpw));*/
fpr = fopen("conftes0", "r");
return fread(array, 1, 7, fpr);
}
This returns 0, unless the fsync is turned on. Is this allowed and
intended this way? The ANSI C9x draft (January 18, 7.19.5.2, page 306)
says about fflush's functionality in this case:
... the fflush function causes any unwritten data ... to be
delivered to the host environment to be written to the file ...
I cannot find anything about one file being open as two streams (input
and output) simultaneously, except (7.19.3, page 301):
Whether the same file can be simultaneously open multiple times is
... implementation-defined.
Oh, now we are at it, ANSI C9x (Annex J.2, page 557) says trying to
fflush an input stream causes undefined behaviour, "with or without
the issuance of a diagnostic message". Maybe we should consider
generating some warning?
And another thing that I noticed while at this, fflush.txh says:
Note that @code{fflush} has no effect for streams opened for
reading only.
But fflush.c nevertheless does:
f->_flag &= ~_IOUNGETC;
I assume this *can* have effect on an input stream. Which behaviour is
intented?
--
*Groeten, Michel* _http://www.cs.vu.nl/~mdruiter_
____________
\ /====\ / "You know, Beavis, you need things that suck,
\/ \/ to have things that are cool", Butt-Head.
- Raw text -