access
Purpose
Determines the accessibility of a file.
Syntax
#include <unistd.h>
int access (path, amode)
char *path;
int amode;
Description
The access system call checks the accessibility of the
file specified by the path parameter, using the real user
ID in place of the effective user ID and the real group
ID in place of the effective group ID. If the Distrib-
uted Services licensed program is installed on your
system, this path can cross into another node. The
access system call checks the named file to see if the
type of access specified by the amode parameter is per-
mitted.
The bit pattern contained in amode is constructed by log-
ically OR-ing 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.
The owner of a file has access checked with respect to
the owner read, write, and execute mode bits. Members of
the file's group other than the owner have access checked
with respect to the group mode bits. All others have
access checked with respect to the other mode bits.
Return Value
If the requested access is permitted, a value of 0 is
returned. If the requested access is denied, a value of
-1 is returned and errno is set to indicate the error.
Diagnostics
Access to the file is denied if one or more of the fol-
lowing are true:
ENOTDIR A component of the path prefix is not a direc-
tory.
ENOENT Read, write, or execute (search) permission is
requested for a null path name.
ENOENT The named file does not exist.
EACCES Search permission is denied on a component of
the path prefix.
EACCES Permission bits of the file mode do not permit
the requested access.
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 parameter &pointsout..
ESTALE The process's root or current directory is
located in a virtual file system that has been
unmounted.
If Distributed Services is installed on your system,
access can also fail if one or more of the following are
true:
EDIST The server has blocked new inbound
requests.
EDIST Outbound requests are currently blocked.
EDIST The server has a release level of Distrib-
uted Services that cannot communicate with
this node.
EAGAIN The server is too busy to accept the
request.
ESTALE The file descriptor for a remote file has
become obsolete.
EPERM The translate tables of the server did not
contain any entry for either the effective
user ID or effective group ID of the
calling process.
ENODEV The named file is a remote file located on
a device that has been unmounted at the
server.
ENOMEM Either this node or the server does not
have enough memory available to service the
request.
ENOCONNECT An attempt to establish a new network con-
nection with a remote node failed.
EBADCONNECT An attempt to use an existing network con-
nection with a remote node failed.
Related Information
In this book: "chmod" and "stat, fstat."