misc/108118: Files cache their eof status
Trenton Schulz
twschulz at trolltech.com
Fri Jan 19 14:30:18 UTC 2007
>Number: 108118
>Category: misc
>Synopsis: Files cache their eof status
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Fri Jan 19 14:30:17 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator: Trenton Schulz
>Release: FreeBSD 6.0 (reproduced on 6.2-RC as well)
>Organization:
Trolltech ASA
>Environment:
FreeBSD stimpy.troll.no 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Wed Dec 7 09:49:59 CET 2005 root at stimpy.troll.no:/usr/obj/usr/src/sys/SMP i386
>Description:
When opening one file handle for reading binary and another for writing binary, one can write a byte, flush the file, and then attempt to read two bytes, the function will fail to read the one byte.
This does not happen on HP-UX, AIX, or Linux
>How-To-Repeat:
#include <stdio.h>
#include <assert.h>
int main()
{
FILE *writeFile;
FILE *readFile;
char readChar;
int i;
writeFile = fopen("/tmp/fooFile", "wb");
readFile = fopen("/tmp/fooFile", "rb");
for (i = 0; i < 2; i++) {
fwrite("a", 1, 1, writeFile);
fflush(writeFile);
assert(fread(&readChar, 1, 2, readFile) > 0);
}
return 0;
}
>Fix:
The programmer can call fseek() and try again. But it's a bit of second guessing. I guess it shouldn't cache the eof check.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list