Linux has the O_PATH
flag to open() which allows one to get a fd to be used in fstat, fcntl and others without actually opening the file for reading (or having permissions to do so). However the O_PATH
flag is Linux specific.
Is there an equivalent to the O_PATH
flag to open() in MacOS? For example, how can I use fstat() on a file I don't have read permissions for?
macOS doesn't have an equivalent to O_PATH
, so it's impossible to have a reference to a file without opening it. Regarding the one bit of functionality that you mentioned, you can call stat
with a given file path as long as you have "execution" rights to its parent directory, regardless of whether you have any rights to that file.