What's the best way to determine if a file already exists? #24
-
[Originally asked 2019-11-06] Some Googling has revealed a few POSIX possibilities, namely: access(): Unfortunately, this is not supported by the Reliance Edge as far as I can see. So, I am concluding that the only way to know if a file exists (given its name) is to use red_opendir(), red_readdir(), red_closedir() to find the file. This does not seem that efficient... Is there a better way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Our engineers have suggested that you consider using red_open() without the RED_O_CREAT flag. If the file exists, it succeeds; if the file does not exist, it fails with the RED_ENOENT errno. Also note: |
Beta Was this translation helpful? Give feedback.
Our engineers have suggested that you consider using red_open() without the RED_O_CREAT flag. If the file exists, it succeeds; if the file does not exist, it fails with the RED_ENOENT errno.
Also note:
If the file is already open, opening it again would open another independent file descriptor, and if that file descriptor is unneeded, it can be closed (which wouldn't affect other file descriptors for the same file).