I\'ve been doing some shell writing and came across a recommendation for access() to check whether a file exists, can be read, etc. Seems super easy to implement and faster
The pattern seems to be calling access()
or stat()
to determine whether you can open a file, and then opening it if you have permission.
Instead, it's usually better just to go ahead and try to open it, and then check whether the attempt succeeded (and if not, why). This avoids the time interval between the check and the attempt to open the file.