From owner-freebsd-standards@FreeBSD.ORG Wed Mar 3 19:22:17 2004 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 810F816A4CF; Wed, 3 Mar 2004 19:22:17 -0800 (PST) Received: from mailout2.pacific.net.au (mailout2.pacific.net.au [61.8.0.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id C415A43D31; Wed, 3 Mar 2004 19:22:16 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87])i243MCnX023033; Thu, 4 Mar 2004 14:22:12 +1100 Received: from gamplex.bde.org (katana.zip.com.au [61.8.7.246]) i243MA5c032424; Thu, 4 Mar 2004 14:22:11 +1100 Date: Thu, 4 Mar 2004 14:22:09 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: David Schultz In-Reply-To: <20040303161532.GA27304@VARK.homeunix.com> Message-ID: <20040304140533.Y5030@gamplex.bde.org> References: <20040303144451.T5253@gamplex.bde.org> <0805074F-6CC9-11D8-9000-000393BB9222@queasyweasel.com> <20040303161532.GA27304@VARK.homeunix.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: standards@freebsd.org Subject: Re: Another conformance question... This time fputs(). X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Mar 2004 03:22:17 -0000 On Wed, 3 Mar 2004, David Schultz wrote: > On Wed, Mar 03, 2004, Bruce Evans wrote: > > This is the only failure case. It bogusly returns EOF instead of boolean > > true. We can set errno to EBADF here if we have no idea why __SRW is > > clear. But we should know. I think the cases are: > > (1) a normal fopen() for reading only. Then EBADF is correct. > > (2) funopen() with no writer, or fropen(). I think this can be determined > > by checking the function pointer that we write through. Then write is > > just unsupported and an errno like ENOTSUP is better than EBADF. > > (3) otherwise, we will call the underlying function and there is no problem > > here. The underlying function just needs to set errno if it fails, and > > old ones probably don't. > > So the only immediate problem with returning EBADF in all cases seems to be > > in case (2) which is not very interesting. > > One could argue that EBADF is a perfectly reasonable error code to > return in case (2) as well. It is consistent with the way other > types of stdio streams work. Specifically, if the stream isn't > writable (either because it was opened read-only and we don't have > permission or because it was opened without a writefn and we don't > support it) then we should get a single error code that reflects > the fact that the stream isn't writable. The fputs(3) man page > even says: > > [EBADF] The _stream_ argument is not a writable stream. > > It doesn't say anything about why the stream is not writable. > Thus, there shouldn't be a problem with simply setting errno to > EBADF in all failure cases in __swsetup(). I would argue that that is a bug in the fputs man page. It clearly doesn't consider the case of funopen()'d streams, and fputs() never actually set errno to EBADF like the man page says. However, errno is set EBADF is set explicitly in several other places irrespective of the destination of the output, and its too late too change all of these and wrong to be inconstent with them: fclose: EOF/EBADF if the stream is not open fflush: EOF/EBADF if the stream is not writable fpurge: EOF/EBADF if the stream is not open __fvwrite: recently changed __srefil: EOF/EBADF if the stream is not open for reading. __srefil is similar to the function behind cantwrite(), namely __swsetup, except it is for reading instead of writing and it sets EBADF. The man page for fflush and fpurge documents EBADF explicitly, but the man page for fclose only has generalities about errno. Bruce