ACCESS
Section: System Calls (2)
Updated: August 1, 1992
Index
Return to Main Contents
NAME
access - determine accessibility of file
SYNOPSIS
#include <sys/file.h> /* POSIX applications #include <unistd.h> */
#define R_OK 4 /* test for read permission */
#define W_OK 2 /* test for write permission */
#define X_OK 1 /* test for execute (search) permission */
#define F_OK 0 /* test for presence of file */
int access(const char *path, int mode);
DESCRIPTION
The
access
function checks the accessibility
of the file whose name is given by
path
for the file access permissions
indicated by
mode.
The value of
mode
is either the bitwise inclusive OR of the
access permissions (R_OK, W_OK and X_OK),
or the existence test (F_OK),
which cause
access
to check whether the directories leading to the file can be
searched and the file exists.
The real user ID and the group access list
(including the real group ID)
are used in verifying permission,
so this call is useful to set-UID programs.
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 may be created there);
a file may look executable, but
execve(2)
will fail unless it is in proper format.
RETURN VALUE
If
path
cannot be found or if any of the desired access modes would
not be granted, then a -1 value is returned and
errno
is set to indicate the error.
Otherwise, a value of zero is returned.
ERRORS
If any of the following conditions occurs,
access
returns -1 and sets
errno
to the corresponding value:
- [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]
-
The
path
argument points outside the process's allocated address space.
- [EINVAL]
-
The pathname contains a character with the high-order bit set.
- [EIO]
-
An I/O error occurred while reading from or writing to the file system.
- [ELOOP]
-
Too many symbolic links were encountered in translating the pathname.
- [ENAMETOOLONG]
-
A component of
path
exceeds 255 characters,
or the entire pathname exceeds 1023 characters.
For POSIX applications these values are given
by the constants {NAME_MAX} and {PATH_MAX}, respectively.
- [ENOENT]
-
The named file does not exist or
path
points to an empty string.
- [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.
- [ETXTBSY]
-
Write access is requested for a pure procedure (shared text)
file that is being executed.
SEE ALSO
chmod(2),
stat(2) or stat(2P)
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUE
-
- ERRORS
-
- SEE ALSO
-
This document was created by
man2html,
using the manual pages.
Time: 17:23:01 GMT, March 25, 2025