++ccn as it is obviously much better to check for the existence of a directory before trying to open it and warn on failure | [reply] |
as it is obviously much better to check for the existence of a directory before trying to open it and warn on failure
That might be OK here, but in the general case it is not, because of race conditions. If you check for the existence of a directory, and then open it, it might be deleted by another process between these two operations.
Thus you have to do the error checking anyway, and don't gain anything by another call to stat (which most file test ops do).
That's why the general philosophy with file access and IO is "try and see if it worked", not "first test if it might work, and then try".
| [reply] |
Thanks a lot svenXY and ccn
| [reply] |