This is the mail archive of the
libc-hacker@sourceware.cygnus.com
mailing list for the glibc project.
libio fflush() bug
- To: libc-hacker@cygnus.com
- Subject: libio fflush() bug
- From: Thorsten Kukuk <kukuk@weber-eb.uni-paderborn.de>
- Date: Fri, 7 Aug 1998 19:30:22 +0200
- Reply-To: kukuk@weber-eb.uni-paderborn.de
Hello,
I have found a big problem. If you do fseek/fread/fflush, the file pointer
is set to the end of the file. If you don't call fseek, the pointer is set
correct to the next byte after the last read one.
I have attached a test program and a patch against libio/fileops.c. Could
somebody, who knows more about the internal, check, if my patch is correct ?
Thorsten
--
Thorsten Kukuk kukuk@vt.uni-paderborn.de
http://www-vt.uni-paderborn.de/~kukuk
Linux is like a Vorlon. It is incredibly powerful, gives terse,
cryptic answers and has a lot of things going on in the background.
#include <stdio.h>
int
main (void)
{
FILE *fp;
long entry = 0;
int before, after;
fp = fopen ("fflush_bug.c", "r+");
fseek (fp, 0, SEEK_SET);
fread (&entry, 4, 1, fp);
before = ftell (fp);
fflush (fp);
after = ftell (fp);
fclose (fp);
printf ("ftell() before fflush(): %d, after fflush(): %d\n", before, after);
if (before == after)
return 0;
else
return 1;
}
1998-08-07 Thorsten Kukuk <kukuk@vt.uni-paderborn.de>
* libio/fileops.c (_IO_file_sync): Fix file pointer position.
diff -u glibc-2.0.95/libio/fileops.c libc-work/libio/fileops.c
--- glibc-2.0.95/libio/fileops.c Thu Jul 23 07:43:58 1998
+++ libc-work/libio/fileops.c Fri Aug 7 19:01:40 1998
@@ -437,7 +437,7 @@
/* char* ptr = cur_ptr(); */
if (fp->_IO_write_ptr > fp->_IO_write_base)
if (_IO_do_flush(fp)) return EOF;
- delta = fp->_IO_read_ptr - fp->_IO_read_end;
+ delta = fp->_IO_read_base - fp->_IO_read_ptr;
if (delta != 0)
{
#ifdef TODO
@@ -446,7 +446,7 @@
#endif
_IO_off64_t new_pos = _IO_SYSSEEK (fp, delta, 1);
if (new_pos != (_IO_off64_t) EOF)
- fp->_IO_read_end = fp->_IO_read_ptr;
+ fp->_IO_read_base = fp->_IO_read_ptr;
#ifdef ESPIPE
else if (errno == ESPIPE)
; /* Ignore error from unseekable devices. */