This type of "check if I can access something" is always easiest solved by actually trying to do what it is you actually want to do, carefully checking for errors at each stage.
Anything else is subject to TOCTOU anyway, so it will not really help to "precheck" things - you still need a lot of checking in the code that does the actual work.