Method access()
- Method
access
intaccess(stringpath,string|voidmode)- Description
access() checks if the calling process can access the file
path. Symbolic links are dereferenced.- Parameter
mode The
modespecifies the accessibility checks to be performed, and is either not specified or empty, in which case access() just tests if the file exists, or one or more of the characters"rwx".r, w, and x test whether the file exists and grants read, write, and execute permissions, respectively.
The check is done using the calling process's real UID and GID, rather than the effective IDs as is done when actually attempting an operation (e.g., open(2)) on the file. This allows set-user-ID programs to easily determine the invoking user's authority.
If the calling process is privileged (i.e., its real UID is zero), then an X_OK check is successful for a regular file if execute permission is enabled for any of the file owner, group, or other.
- Returns
1When the file is accessible using the given permissions.
0When the file is not accessible, in which case errno is set to one of the following values:
EACCESSAccess denied.
ELOOPToo many symbolic links.
ENAMETOOLONGThe path is too long.
ENOENTThe file does not exist.
ENOTDIROne of the directories used in
pathis not, in fact, a directory.EROFSThe filesystem is read only and write access was requested.
Other errors can occur, but are not directly related to the requested path, such as
ENOMEM, etc.- See also