1ACCESS(2)                  Linux Programmer's Manual                 ACCESS(2)
2
3
4

NAME

6       access - check real user's permissions for a file
7

SYNOPSIS

9       #include <unistd.h>
10
11       int access(const char *pathname, int mode);
12

DESCRIPTION

14       access()  checks  whether the calling process can access the file path‐
15       name.  If pathname is a symbolic link, it is dereferenced.
16
17       The mode specifies the accessibility check(s) to be performed,  and  is
18       either the value F_OK, or a mask consisting of the bitwise OR of one or
19       more of R_OK, W_OK, and X_OK.  F_OK tests  for  the  existence  of  the
20       file.   R_OK,  W_OK,  and  X_OK test whether the file exists and grants
21       read, write, and execute permissions, respectively.
22
23       The check is done using the calling process's real UID and GID,  rather
24       than the effective IDs as is done when actually attempting an operation
25       (e.g., open(2)) on the file.  This allows set-user-ID programs to  eas‐
26       ily determine the invoking user's authority.
27
28       If the calling process is privileged (i.e., its real UID is zero), then
29       an X_OK check is successful for a regular file if execute permission is
30       enabled for any of the file owner, group, or other.
31

RETURN VALUE

33       On  success (all requested permissions granted, or mode is F_OK and the
34       file exists), zero is returned.  On error (at least  one  bit  in  mode
35       asked  for  a  permission  that is denied, or mode is F_OK and the file
36       does not exist, or some other error  occurred),  -1  is  returned,  and
37       errno is set appropriately.
38

ERRORS

40       access() shall fail if:
41
42       EACCES The requested access would be denied to the file, or search per‐
43              mission is denied for one of the directories in the path  prefix
44              of pathname.  (See also path_resolution(7).)
45
46       ELOOP  Too many symbolic links were encountered in resolving pathname.
47
48       ENAMETOOLONG
49              pathname is too long.
50
51       ENOENT A component of pathname does not exist or is a dangling symbolic
52              link.
53
54       ENOTDIR
55              A component used as a directory in pathname is not, in  fact,  a
56              directory.
57
58       EROFS  Write  permission  was  requested for a file on a read-only file
59              system.
60
61       access() may fail if:
62
63       EFAULT pathname points outside your accessible address space.
64
65       EINVAL mode was incorrectly specified.
66
67       EIO    An I/O error occurred.
68
69       ENOMEM Insufficient kernel memory was available.
70
71       ETXTBSY
72              Write access was requested to an executable which is being  exe‐
73              cuted.
74

CONFORMING TO

76       SVr4