Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Jan 2007 14:25:53 GMT
From:      Trenton Schulz<twschulz@trolltech.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/108118: Files cache their eof status
Message-ID:  <200701191425.l0JEPr1Z072787@www.freebsd.org>
Resent-Message-ID: <200701191430.l0JEUIL6051104@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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@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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200701191425.l0JEPr1Z072787>