access()

NAME

access() - check access permissions of a file or pathname

SYNOPSIS

#include <unistd.h>

int access (const char *path, int mode)

DESCRIPTION

The access(2) function checks that the file named by path is actually accessible in terms of the access permissions indicated by mode. Mode is the bitwise inclusive OR of the access permissions to be checked; the permissions are:

R_OK
Read permission
W_OK
Write permission
X_OK
Execute/search permission
F_OK
File existence

The function checks all of path's components for access permissions (including F_OK).

The function uses the program's real user ID, not the effective user ID; it's normally used by setuid programs to check their actions.

Even if a process has appropriate privileges and indicates success for X_OK, the file may not actually have execute permission bits set. Likewise for R_OK and W_OK.

RETURN VALUES

The access(2) function returns 0 on success, or -1 if path cannot be found or if any of the desired access modes wouldn't be granted.

ERRORS

Access to the file is denied if:

[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. The owner of a file has permission checked with respect to the "owner" read, write, and execute mode bits, members of the file's group other than the owner have permission checked with respect to the "group" mode bits, and all others have permissions checked with respect to the "other" mode bits.
[EFAULT]
Path points outside the process's allocated address space.
[EINVAL]
The pathname is not valid, or the file is on a device that does not support the call.
[EIO]
An I/O error occurred while reading from or writing to the file system.
[ENAMETOOLONG]

A component of a pathname exceeded characters, or an entire path name exceeded characters.
[ENOENT]
The named file does not exist.
[ELOOP]
Too many symbolic links were encountered in translating the pathname.
[ENOTDIR]
A component of the path prefix is not a directory.
[EROFS]
Write access is requested for a file on a read-only file system.

SEE ALSO

chmod(2)

stat(2)