Date: Sat, 19 Jun 2004 11:56:43 +0200 From: Radim Kolar <hsn@netmag.cz> To: freebsd-arch@freebsd.org Subject: Re: fflush() on readonly files Message-ID: <20040619095642.GA67130@sanatana.dharma> In-Reply-To: <20040610025439.GA11655@cat.robbins.dropbear.id.au> References: <20040609154040.GA26229@asura.bsd> <20040610021356.GA4990@VARK.homeunix.com> <20040610025439.GA11655@cat.robbins.dropbear.id.au>
next in thread | previous in thread | raw e-mail | index | archive | help
> > > 3 - Correct some programs depending on this
> > Are there any such programs?
Today I have stepped on another example: advancecomp (in ports):
Code for returning size of file: lib/fz.c
542 /**
543 * Get the size of the file.
544 */
545 long fzsize(adv_fz* f)
546 {
547 if (f->type == fz_file) {
548 struct stat st;
549 if (fflush(f->f) != 0) {
550 return -1;
551 }
> The behavior of fflush() on a read-only stream is not defined by any
> relevant standards. It is a no-op.
Returning an error is not no-op. It is a failure.
There are 2 cases:
1) Program knows that he has r/o fd and calls fflush() on it.
> In my experience, fflush() is only called on input streams when the Microsoft
> behavior is expected.
2) Program do not knows that he has r/o fd and calls fflush() as part of his normal operation. For example fflush()+fstat() pairs and fflush()+fclose() pairs.
This programs expects that fflush() on r/o files do not fails.
I am interested in solving case #2. I have no troubles with #1 programs; there are not a very common.
> Bottom line: learn C, fix your code.
There are other languages also. Major problem with this behavior lies in
various Python scripts. When they calls fflush() on r/o fd, exception is thrown
and aborts program. They often calls fflush before close in class which
supports both r/o and r/w fd and there is no way to check type of passed
descriptor.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040619095642.GA67130>
