From owner-freebsd-arch@FreeBSD.ORG Tue Mar 2 02:37:54 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 BBEC516A4CE for ; Tue, 2 Mar 2004 02:37:54 -0800 (PST) Received: from srv01.sparkit.no (srv01.sparkit.no [193.69.116.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id 328B143D39 for ; Tue, 2 Mar 2004 02:37:54 -0800 (PST) (envelope-from eivind@FreeBSD.org) Received: from ws ([193.69.114.88]) by srv01.sparkit.no (8.12.10/8.12.10) with ESMTP id i22AbmSD018175; Tue, 2 Mar 2004 11:37:48 +0100 (CET) (envelope-from eivind@FreeBSD.org) Received: from ws (localhost [127.0.0.1]) by ws (8.12.9/8.12.10) with ESMTP id i22Aajmd056475; Tue, 2 Mar 2004 10:36:45 GMT (envelope-from eivind@ws) Received: (from eivind@localhost) by ws (8.12.9/8.12.10/Submit) id i22AaiAw056466; Tue, 2 Mar 2004 10:36:45 GMT (envelope-from eivind) Date: Tue, 2 Mar 2004 10:35:43 +0000 From: Eivind Eklund To: "Jordan K. Hubbard" Message-ID: <20040302103543.GF27008@FreeBSD.org> References: <1060DC2A-6C31-11D8-9000-000393BB9222@queasyweasel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1060DC2A-6C31-11D8-9000-000393BB9222@queasyweasel.com> User-Agent: Mutt/1.5.4i cc: freebsd-arch@FreeBSD.org Subject: Re: Another conformance question... This time fputs(). 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: Tue, 02 Mar 2004 10:37:54 -0000 On Tue, Mar 02, 2004 at 02:04:59AM -0800, Jordan K. Hubbard wrote: > Given that it's just not kosher to write on a read-only fp and get no > error back at all, I would argue (though not passionately) for the > following diff to libc: > > --- stdio/fvwrite.c 22 Mar 2002 21:53:04 -0000 1.15 > +++ stdio/fvwrite.c 2 Mar 2004 08:40:25 -0000 > @@ -43,6 +43,7 @@ > #include > #include > #include > +#include > #include "local.h" > #include "fvwrite.h" > > @@ -67,8 +68,10 @@ > if ((len = uio->uio_resid) == 0) > return (0); > /* make sure we can write */ > - if (cantwrite(fp)) > + if (cantwrite(fp)) { > + errno = EACCES; > return (EOF); > + } > > #define MIN(a, b) ((a) < (b) ? (a) : (b)) > #define COPY(n) (void)memcpy((void *)fp->_p, (void *)p, > (size_t)(n)) > > That gives us this behavior for our little test program: > > errno = 13, rc = -1 > fwrite errno = 13, rc = 0 > > In both cases, we get EACCES for fputs() or fwrite() attempts on a > read-only file pointer pointing to a read-only device, something we'd > expect to get "permission denied" for I think. In the case where we > open the fp for write access, the FreeBSD behavior is unchanged: Based on a quick reading of the SUSv2 putc manpage[*] (which is what documents the errors for fwrite and fputs), I'd say the following error seems appropriate: [EBADF] The file descriptor underlying stream is not a valid file descriptor open for writing. If we open the file for writing, I think we should get: [ENXIO] A request was made of a non-existent device, or the request was outside the capabilities of the device. EACCES is not allowed at all from these calls. Eivind. [*] The fputc manpage is at: http://www.opengroup.org/onlinepubs/007908799/xsh/fputc.html