From: Martin Str|mberg Message-Id: <200102121851.TAA22673@father.ludd.luth.se> Subject: Re: Bug000323 In-Reply-To: from Eli Zaretskii at "Feb 12, 2001 12:59:20 pm" To: djgpp-workers AT delorie DOT com Date: Mon, 12 Feb 2001 19:51:00 +0100 (MET) X-Mailer: ELM [version 2.4ME+ PL54 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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 #include #include #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