From owner-freebsd-arch@FreeBSD.ORG Sat Jun 19 09:58:38 2004 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EC78716A535 for ; Sat, 19 Jun 2004 09:58:38 +0000 (GMT) Received: from mail.tiscali.cz (stateless2.tiscali.cz [213.235.135.71]) by mx1.FreeBSD.org (Postfix) with ESMTP id B281743D1F for ; Sat, 19 Jun 2004 09:58:38 +0000 (GMT) (envelope-from hsn@netmag.cz) Received: from sanatana.dharma (212.90.236.212) by mail.tiscali.cz (6.7.021) id 40B1F78600B53DCB for freebsd-arch@freebsd.org; Sat, 19 Jun 2004 11:58:23 +0200 Received: from hsn@localhost by sanatana.dharma (Exim 4.33_1 FreeBSD) id 1BbcaZ-000JIF-1y for ; Sat, 19 Jun 2004 11:56:43 +0200 Date: Sat, 19 Jun 2004 11:56:43 +0200 From: Radim Kolar To: freebsd-arch@freebsd.org Message-ID: <20040619095642.GA67130@sanatana.dharma> Mail-Followup-To: freebsd-arch@freebsd.org References: <20040609154040.GA26229@asura.bsd> <20040610021356.GA4990@VARK.homeunix.com> <20040610025439.GA11655@cat.robbins.dropbear.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040610025439.GA11655@cat.robbins.dropbear.id.au> User-Agent: Mutt/1.5.6i Subject: Re: fflush() on readonly files X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Jun 2004 09:58:39 -0000 > > > 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.