Mail Archives: djgpp-workers/2001/02/12/13:51:20
According to Eli Zaretskii:
>
> On Mon, 12 Feb 2001, Martin Stromberg wrote:
>
> > The question is: did you find another real bug in fflush()?
>
> Yes, I think so. See the source below: it never pays attention to the
> append flag. So if you fseek somewhere, then fflush the stream, the data
> doesn't go to the correct place: the end of file.
Ok, I tried to cook up a program to see this bug. This is what I came up with:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#define FILE_NAME "fflush.dat"
#define LENGTH_OF_ZEROES (10240)
int
main(void)
{
char ch;
FILE *f;
int i, ret;
int status = 0; /* Return value. */
f = fopen(FILE_NAME, "w");
for( i = 0; i < LENGTH_OF_ZEROES; i++ )
{
fprintf(f, "%c", '\0');
}
fclose(f);
f = fopen(FILE_NAME, "a");
fprintf(f, "hello, there\n");
/* fflush(f) tried here but no bug. */
fclose(f);
f = fopen(FILE_NAME, "a");
fseek(f, 10, SEEK_SET);
fprintf(f, "hello, there\n");
/* fflush(f) tried here but no bug. */
fclose(f);
f = fopen(FILE_NAME, "r");
for( i = 0; i < LENGTH_OF_ZEROES; i++ )
{
ret = fscanf(f, "%c", &ch);
if( ret != 1 )
{
fprintf(stderr, "Failed to read expected 0 at index %d.\n", i);
status++;
}
else if( ch != '\0' )
{
fprintf(stderr, "Unexpected char '%c' (%d) found while expecting 0 at index %d.\n", ch, ch, i);
status++;
}
}
fclose(f);
return status;
}
But I still see no bug; the "hello there"s end up at the end. Any
ideas on how to get it to manifest itself?
Right,
MartinS
- Raw text -