Re: sorting readdir output? [message #184023 is a reply to message #184022] |
Mon, 02 December 2013 21:33 |
Christoph Michael Bec
Messages: 207 Registered: June 2013
Karma:
|
Senior Member |
|
|
Richard Yates wrote:
> I understand the warning as it applies to many functions. Perhaps I
> should have asked why there would ever be a valid result of a
> directory read that evaluates to false. In practice, reading his own
> directory, would he ever actually encounter a file named "0" or
> "false"?
Using the explicit check for !== FALSE seems reasonable anyway. A file
named "0" might exists, and maybe there are some strange filenames that
are returned as empty string (not sure, if that could happen, though).
The filename "false", however, == TRUE.
OTOH, implicitely checking for == FALSE, would catch an error where
opendir() returned FALSE (for instance, because the directory does not
exist). In this case the OP's code would call readdir() with FALSE as
argument, what would cause readdir() to return NULL.
A better solution would check for the return value of opendir() in the
first place.
--
Christoph M. Becker
|
|
|