Date: Fri, 24 Jan 2014 15:34:04 -0600 From: Bryan Drewery <bryan@shatow.net> To: Bruce Evans <brde@optusnet.com.au> Cc: bapt@FreeBSD.org, freebsd-standards@FreeBSD.org, Jilles Tjoelker <jilles@stack.nl> Subject: Re: closedir(3) handling NULL Message-ID: <20140124213404.GC73838@admin.xzibition.com> In-Reply-To: <20140125041504.Y986@besplex.bde.org> References: <20140124014105.GC37334@admin.xzibition.com> <20140124132435.GA90996@stack.nl> <20140124165509.GA73838@admin.xzibition.com> <20140125041504.Y986@besplex.bde.org>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --] On Sat, Jan 25, 2014 at 06:00:08AM +1100, Bruce Evans wrote: > On Fri, 24 Jan 2014, Bryan Drewery wrote: > > > 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. POSIX > >>> [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.html > > > I do think that improving portability is important. Even against sloppy > > coding. Applications developed for Linux are fine passing NULL to closedir(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. > > 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. > > @ NOTES > @ The fclose() function does not handle NULL arguments; they will result in > @ a segmentation violation. This is intentional - it makes it easier to > @ make sure programs written under FreeBSD are bug free. This behaviour is > @ an implementation detail, and programs should not rely upon it. > > 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; > % > % + if (dirp == NULL) { > % + errno = EBADF; > % + return (-1); > % + } > % + > > Style bug (extra blank line). > > % if (__isthreaded) > % _pthread_mutex_lock(&dirp->dd_lock); > > Example of normal style (no extra blank line after an if statement). > > Extra blank lines are especially not needed after return statements since > return statements obviously don't fall through. > > % fd = dirp->dd_fd; > % @@ -71,6 +76,10 @@ fdclosedir(DIR *dirp) > % int > % closedir(DIR *dirp) > % { > % + int fd; > % + > % + if ((fd = fdclosedir(dirp)) == -1) > % + return (-1); > % > > Style bug (extra blank line). > > There is no man page for fdclosedir(3). It is in directory(3), but someone > 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. > > % - return (_close(fdclosedir(dirp))); > % + return (_close(fd)); > % } Bryan Drewery [-- Attachment #2 --] -----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-----help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140124213404.GC73838>
