From owner-freebsd-standards@FreeBSD.ORG Fri Jan 24 21:34:09 2014 Return-Path: Delivered-To: freebsd-standards@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 771E6942 for ; Fri, 24 Jan 2014 21:34:09 +0000 (UTC) Received: from secure.xzibition.com (secure.xzibition.com [173.160.118.92]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1B0431AB3 for ; Fri, 24 Jan 2014 21:34:08 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=shatow.net; h=date:from:to :cc:subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=sweb; b=K2b4/MV2XrwbyFLpr7FYL8dX2K25P6W1D fduJxBKpxf/nHJPnUNcUiCVQxTdg+Vkdp7RkQ6mwXDAhxM3uGEY2hi8h6Iw4jSH2 xpeIPNxX3YOJ/fa1G3A0i9fzN1BqpoDMuxbAGuHesiPm7CP6y/KbYEMvFStUZWva XVvAzQE1cA= DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=shatow.net; h=date:from :to:cc:subject:message-id:references:mime-version:content-type :in-reply-to; s=sweb; bh=URfIPbyXaIvhl8agUKFFyqpA4ElOwRXLHUGA7Ug Cfus=; b=OzhMwfEO55TB5+Y2J6aLbRdeFCwfhErbWC24lydnyyOhV8EVUxW2Kz0 vXYMC0fGalnWoY6Guj9U3dtD8YY4BAmwOQ9rBlCuuCV4Ib1eQLNjXMM9Vd6wGon5 MURK0xH8Ua1h2pSXQNFP1IWennpr8QkwXdZl912+qRZcnaQ6vAWI= Received: (qmail 91505 invoked from network); 24 Jan 2014 15:34:05 -0600 Received: from unknown (HELO admin.xzibition.com) (bryan@shatow.net@173.160.118.90) by sweb.xzibition.com with ESMTPA; 24 Jan 2014 15:34:05 -0600 Date: Fri, 24 Jan 2014 15:34:04 -0600 From: Bryan Drewery To: Bruce Evans Subject: Re: closedir(3) handling NULL Message-ID: <20140124213404.GC73838@admin.xzibition.com> References: <20140124014105.GC37334@admin.xzibition.com> <20140124132435.GA90996@stack.nl> <20140124165509.GA73838@admin.xzibition.com> <20140125041504.Y986@besplex.bde.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="TiqCXmo5T1hvSQQg" Content-Disposition: inline In-Reply-To: <20140125041504.Y986@besplex.bde.org> User-Agent: Mutt/1.5.22 (2013-10-16) Cc: bapt@FreeBSD.org, freebsd-standards@FreeBSD.org, Jilles Tjoelker X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jan 2014 21:34:09 -0000 --TiqCXmo5T1hvSQQg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jan 25, 2014 at 06:00:08AM +1100, Bruce Evans wrote: > On Fri, 24 Jan 2014, Bryan Drewery wrote: >=20 > > On Fri, Jan 24, 2014 at 02:24:35PM +0100, Jilles Tjoelker wrote: > >> On Thu, Jan 23, 2014 at 07:41:05PM -0600, Bryan Drewery wrote: > >>> I found that Linux handles closedir(NULL) fine and returns EINVAL. PO= SIX > >>> [1] specifies that EBADF should be returned if "The dirp argument does > >>> not refer to an open directory stream" > >> > >>> [1] http://pubs.opengroup.org/onlinepubs/009696799/functions/closedir= =2Ehtml >=20 > > I do think that improving portability is important. Even against sloppy > > coding. Applications developed for Linux are fine passing NULL to close= dir(3), > > which leads to a style of coding that does not reveal itself to be a > > problem on FreeBSD until an edge case comes up. >=20 > This unimproves portability. FreeBSD intentionally does the opposite for > fclose(): from fclose(3): IMHO we should handle NULL gracefully in all places instead of having hidden surprises. >=20 > @ NOTES > @ The fclose() function does not handle NULL arguments; they will re= sult in > @ a segmentation violation. This is intentional - it makes it easie= r to > @ make sure programs written under FreeBSD are bug free. This behav= iour is > @ an implementation detail, and programs should not rely upon it. >=20 > It would be good to do the same thing for garbage stream pointers. [...] > % diff --git lib/libc/gen/closedir.c lib/libc/gen/closedir.c > % index 88ded37..d7a5bdb 100644 > % --- lib/libc/gen/closedir.c > % +++ lib/libc/gen/closedir.c > % @@ -53,6 +53,11 @@ fdclosedir(DIR *dirp) > % { > % int fd; > %=20 > % + if (dirp =3D=3D NULL) { > % + errno =3D EBADF; > % + return (-1); > % + } > % + >=20 > Style bug (extra blank line). >=20 > % if (__isthreaded) > % _pthread_mutex_lock(&dirp->dd_lock); >=20 > Example of normal style (no extra blank line after an if statement). >=20 > Extra blank lines are especially not needed after return statements since > return statements obviously don't fall through. >=20 > % fd =3D dirp->dd_fd; > % @@ -71,6 +76,10 @@ fdclosedir(DIR *dirp) > % int > % closedir(DIR *dirp) > % { > % + int fd; > % + > % + if ((fd =3D fdclosedir(dirp)) =3D=3D -1) > % + return (-1); > % >=20 > Style bug (extra blank line). >=20 > There is no man page for fdclosedir(3). It is in directory(3), but someo= ne > forgot to add fdclosedir.3 to MLINKS. fdopendir.3 is unsorted in MLINKS > instead of missing. Thanks for the style comments. I am now aware. I am fixing the MLINKS issues. >=20 > % - return (_close(fdclosedir(dirp))); > % + return (_close(fd)); > % } Bryan Drewery --TiqCXmo5T1hvSQQg Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iQJ8BAEBCgBmBQJS4txLXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQzNkZFQkU5OTJGNTI4MERGNDgxMTM2MkE2 RTc4MkFDMDNDOUIwQ0Y5AAoJEG54KsA8mwz5bT0P+QEJzLChOFBCg7IYb26thkhM lUy1L/EKwPiGDNQTrNUY4SiXhW0SuZDpa+8MkoRMT5yYqXbMpAOApJLt+2c5bYq0 88Q4TIyVPLnHC9HNM6wtneu802VNx2I2eN/xR4VU6SMKIiwI7mWglIWbi4IldnvI 8rsXb5l3rELrHduekyuJk2qbvY6NnBaL8JB7MJ4F4LDKrToYWV/ZBAiVSANDEcTA L9f27lRK8Z3JgPVngkdZMhU8x0Dmzho7AyJByfu+YxgPvhNSi7vlBBPbCasYTsIn vit/zLXB8zh26T1MPfMpSvK1ktFUt4nZ+aqfb7Pvv413oTRD3VVnaDetXX5gipI7 ZL1+GJuGr87IW0skvaM6MwaFqcASSyry7UNKW8JZoS7RjpW0wIRvvJw9wnMMnCER rxSKJNgVJe4QvWvha1IQrGQjBUlOMruAOWfRq5RhcSAd9UHMeHgjXJEoTBWVuuEW 4+Q3wkeU6/KGIp5546xglCqd7BXomS2yWZXinZe851latXXZfXlZHtgPJb0Dda4H bAzfTxMVoDPhQ/yLfPeph69CVSU+NQLWslnrWM3DGd0imD16o+t+gR3yhjA+GtJY /vWF7ZvYiQIPOzSA7BhLEETYCPwxfgRZeOxAfLjSiZArxhl16tvdPKAgFtrR9xk7 psJzIJ0fwXnVOsli9tUn =8/QF -----END PGP SIGNATURE----- --TiqCXmo5T1hvSQQg--