ACCESS(2) SysV ACCESS(2)
NAME
access - Determine the accessibility of a file
SYNOPSIS
#include <unistd.h>
int access (path, access_mode)
const char *path;
int access_mode;
DESCRIPTION
The access function checks for accessibility of the file specified by a
pathname.
The path argument points to the file pathname. When the path argument
refers to a symbolic link, the access function returns information about
the file pointed to by the symbolic link.
Permission to access all components of the path argument is determined by
using a real user ID instead of an effective user ID, a group access list
(including a real group ID) instead of an effective group ID.
access_mode specifies the type of access. The bit pattern contained in
the access_mode argument is constructed by a logical OR of the following
values:
R_OK Checks read permission.
W_OK Checks write permission.
X_OK Checks execute (search) permission.
F_OK Checks to see if the file exists.
Specifying mode as F_OK (that is, 0) tests whether the directories
leading to the file can be searched and the file exists.
If any access permissions are to be checked, each is checked
individually.
If the process making the call has ROOT privileges, success if returned
for X_OK, R_OK or W_OK -- even if none of these file permission bits are
set.
Notice that only access bits are checked. A directory may be indicated
as writable by access, but an attempt to open it for writing will fail
(although files can be created there); a file may look executable, but
exec will fail unless it is in proper format.
DIAGNOSTICS
Upon successful completion, the access returns a value of 0 (zero).
Otherwise, a value of -1 is returned and errno is set to indicate the
error.
ERRORS
If the access function fails, access to the file specified by the path
argument is denied and errno is set to one of the following values:
[ENOTDIR] A component of the path prefix is not a directory.
[EINVAL] The value of access_mode is invalid.
[ENAMETOOLONG] A component of a pathname exceeded PATH_MAX characters, or
an entire pathname exceeded NAME_MAX characters.
[ENOENT] The named file does not exist or path points to an empty
string.
[EACCES] Permission bits of the file mode do not permit the
requested access, or search permission is denied on a
component of the path prefix.
[EROFS] Write access is requested for a file on a read-only file
system.
[ETXTBSY] Write access is requested for a pure procedure (shared
text) file that is being executed.
[EFAULT] The path argument points outside the process' allocated
address space.
[EINTR] A signal was caught during the access system call.
SEE ALSO
chmod(2), stat(2), chown(2), <unistd.h>.