[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] severe bug in file-exists?

From: Thomas Chust
Subject: Re: [Chicken-users] severe bug in file-exists?
Date: Wed, 28 Sep 2011 16:43:13 +0200

2011/9/28 Christian Kellermann <address@hidden>:
> [...]
> As I see it, this procedure needs an overhaul anyway. If fstat fails
> it returns #f regardless the reason.
> [...]


while it is true that only an ENOENT errno indicates a missing path
component in any file system operation, I also wonder why on earth
anyone would want to use fstat to check for the existence of a file?

To use fstat you first have to open the file, but if it can be opened,
it clearly exists and calling fstat at all is redundant. However, if
it cannot be opened, a large variety of reasons other than
nonexistence of the file can be responsible.

Calling stat instead of fstat and checking for an ENOENT errno would
be an option, but if one is only interested in the existence of the
file it looks like overkill to me to collect all the metainformation
about the file and then throw it away.

I would say that the canonical way to check for file existence is
calling access with the candidate path as first argument and the mode
F_OK as second argument and checking for an ENOENT errno.


When C++ is your hammer, every problem looks like your thumb.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]