closedir(3) handling NULL
Jilles Tjoelker
jilles at stack.nl
Fri Jan 24 22:39:21 UTC 2014
On Fri, Jan 24, 2014 at 03:34:04PM -0600, Bryan Drewery wrote:
> On Sat, Jan 25, 2014 at 06:00:08AM +1100, Bruce Evans wrote:
> > On Fri, 24 Jan 2014, Bryan Drewery wrote:
> > > 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.
In many cases (but possibly not this one), handling NULL "gracefully"
makes it harder to debug the inevitable failure. For example, if
readdir() did not crash when passed a null pointer, a program that fails
to check opendir()'s return value would plough on for longer and it
would be harder to find the problem.
Whether a function that frees something silently does nothing when
passed a null pointer is indeed inconsistent.
--
Jilles Tjoelker
More information about the freebsd-standards
mailing list