Return to BSD News archive
Newsgroups: comp.unix.bsd
Path: sserve!manuel!munnari.oz.au!spool.mu.edu!darwin.sura.net!Sirius.dfn.de!dct.zrz.tu-berlin.de!math.fu-berlin.de!Germany.EU.net!mcsun!sunic!psinntp!psinntp!dg-rtp!ponds.uucp!rivers
From: rivers@ponds.uucp (Thomas David Rivers)
Subject: [386BSD] stdio (fflush and "a+") problems / fix.
Message-ID: <1992Oct3.033742.4726@ponds.uucp>
Keywords: stdio fflush append
Date: Sat, 3 Oct 1992 03:37:42 GMT
Lines: 29
I've discovered the following discrepency in the stdio library w/
regards to opening a stream using fopen("file","a+") and later
calling fflush() on that stream.
[I found this because my Cnews got warnings about closing the news
history file. Everything else is running fine...]
The fopen() call resets the flags to __SRW because of the '+' in
the mode string.
Later on, fflush() checks to ensure that the stream being flushed
is actually writable. To do this, it looks for the __SWR value
in the flags, and *not* __SRW. There is a comment in stdio.h that
implies that __SWR and __SRW will never be set at the same time.
A correction is to change the test at line 51 of fflush.c from :
if ((fp->_flags & __SWR) == 0) {
to
if ((fp->_flags & (__SWR | __SRW)) == 0 ) {
Since either __SWR or __SRW are sufficient for a file to be "writable."
- Dave Rivers -