In reading IEEE Std 1003.1 (POSIX Base Spec) regarding access(), I came across this note:
“The purpose of the faccessat( ) function is to enable the checking of the accessibility of files in directories other than the current working directory without exposure to race conditions. Any part of the path of a file could be changed in parallel to a call to access( ), resulting in unspecified behavior. By opening a file descriptor for the target directory and using the faccessat( ) function it can be guaranteed that the file tested for accessibility is located relative to the desired directory.”
I’m curious to see some GNU C system code examples of this. I’m looking at GNU/Hurd open issues and noted the following:
https://www.gnu.org/software/hurd/open_issues/faccessat.html
faccessat() fails on some cases; in particular when:
- flags does not have AT_EACCESS
- dirfd is not AT_FDCWD
- pathname is not an absolute path
In such case, it will return -1 setting ENOTSUP as errno
Understanding how this failure is happening (for me, relatively new to this type of code) would be aided by examples of proper implementation of the function.