1ACCESS(3P)                 POSIX Programmer's Manual                ACCESS(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       access, faccessat — determine  accessibility  of  a  file  relative  to
14       directory file descriptor
15

SYNOPSIS

17       #include <unistd.h>
18
19       int access(const char *path, int amode);
20       int faccessat(int fd, const char *path, int amode, int flag);
21

DESCRIPTION

23       The  access()  function  shall  check  the  file  named by the pathname
24       pointed to by the path argument for accessibility according to the  bit
25       pattern  contained  in  amode,  using  the real user ID in place of the
26       effective user ID and the real group ID in place of the effective group
27       ID.
28
29       The  value  of  amode  is either the bitwise-inclusive OR of the access
30       permissions to be checked (R_OK, W_OK,  X_OK)  or  the  existence  test
31       (F_OK).
32
33       If  any access permissions are checked, each shall be checked individu‐
34       ally, as described in the Base Definitions volume of POSIX.1‐2008, Sec‐
35       tion  4.4,  File Access Permissions, except that where that description
36       refers to execute permission for a process with appropriate privileges,
37       an implementation may indicate success for X_OK even if execute permis‐
38       sion is not granted to any user.
39
40       The faccessat() function shall be equivalent to the access()  function,
41       except  in  the case where path specifies a relative path. In this case
42       the file whose accessibility is to be determined shall be located rela‐
43       tive to the directory associated with the file descriptor fd instead of
44       the current working directory. If the file descriptor was opened  with‐
45       out  O_SEARCH,  the function shall check whether directory searches are
46       permitted using the current permissions of the directory underlying the
47       file  descriptor.  If the file descriptor was opened with O_SEARCH, the
48       function shall not perform the check.
49
50       If faccessat() is passed the special value AT_FDCWD in the  fd  parame‐
51       ter, the current working directory shall be used and the behavior shall
52       be identical to a call to access().
53
54       Values for flag are constructed by a bitwise-inclusive OR of flags from
55       the following list, defined in <fcntl.h>:
56
57       AT_EACCESS  The checks for accessibility are performed using the effec‐
58                   tive user and group IDs instead of the real user and  group
59                   ID as required in a call to access().
60

RETURN VALUE

62       Upon  successful completion, these functions shall return 0. Otherwise,
63       these functions shall return −1 and set errno to indicate the error.
64

ERRORS

66       These functions shall fail if:
67
68       EACCES Permission bits of the file mode do  not  permit  the  requested
69              access,  or  search  permission  is denied on a component of the
70              path prefix.
71
72       ELOOP  A loop exists in symbolic links encountered during resolution of
73              the path argument.
74
75       ENAMETOOLONG
76              The  length  of  a  component  of  a  pathname  is  longer  than
77              {NAME_MAX}.
78
79       ENOENT A component of path does not name an existing file or path is an
80              empty string.
81
82       ENOTDIR
83              A  component  of  the path prefix names an existing file that is
84              neither a directory nor a symbolic link to a directory,  or  the
85              path  argument  contains  at least one non-<slash> character and
86              ends with one or more trailing <slash> characters and  the  last
87              pathname  component  names  an  existing  file that is neither a
88              directory nor a symbolic link to a directory.
89
90       EROFS  Write access is requested for a file on a read-only file system.
91
92       The faccessat() function shall fail if:
93
94       EACCES fd was not opened with  O_SEARCH  and  the  permissions  of  the
95              directory underlying fd do not permit directory searches.
96
97       EBADF  The  path  argument does not specify an absolute path and the fd
98              argument is neither AT_FDCWD nor a valid  file  descriptor  open
99              for reading or searching.
100
101       ENOTDIR
102              The  path  argument  is  not  an  absolute path and fd is a file
103              descriptor associated with a non-directory file.
104
105       These functions may fail if:
106
107       EINVAL The value of the amode argument is invalid.
108
109       ELOOP  More than {SYMLOOP_MAX} symbolic links were  encountered  during
110              resolution of the path argument.
111
112       ENAMETOOLONG
113              The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
114              tion of a symbolic link produced an intermediate result  with  a
115              length that exceeds {PATH_MAX}.
116
117       ETXTBSY
118              Write  access  is  requested  for a pure procedure (shared text)
119              file that is being executed.
120
121       The faccessat() function may fail if:
122
123       EINVAL The value of the flag argument is not valid.
124
125       The following sections are informative.
126

EXAMPLES

128   Testing for the Existence of a File
129       The following example tests whether a file named myfile exists  in  the
130       /tmp directory.
131
132           #include <unistd.h>
133           ...
134           int result;
135           const char *pathname = "/tmp/myfile";
136
137           result = access (pathname, F_OK);
138

APPLICATION USAGE

140       Additional  values  of amode other than the set defined in the descrip‐
141       tion may be valid; for example, if a system has  extended  access  con‐
142       trols.
143
144       The  use  of  the  AT_EACCESS  value for flag enables functionality not
145       available in access().
146

RATIONALE

148       In early proposals, some inadequacies in the access() function  led  to
149       the creation of an eaccess() function because:
150
151        1. Historical implementations of access() do not test file access cor‐
152           rectly when the process' real user ID is superuser. In  particular,
153           they  always  return  zero when testing execute permissions without
154           regard to whether the file is executable.
155
156        2. The superuser has complete access to all files on a  system.  As  a
157           consequence,  programs started by the superuser and switched to the
158           effective user ID with lesser privileges  cannot  use  access()  to
159           test their file access permissions.
160
161       However,  the  historical  model  of eaccess() does not resolve problem
162       (1), so this volume of POSIX.1‐2008 now allows access()  to  behave  in
163       the  desired  way  because  several  implementations have corrected the
164       problem. It was also argued that problem (2) is more easily  solved  by
165       using  open(), chdir(), or one of the exec functions as appropriate and
166       responding to the error, rather than creating a new function that would
167       not be as reliable. Therefore, eaccess() is not included in this volume
168       of POSIX.1‐2008.
169
170       The sentence concerning appropriate privileges and  execute  permission
171       bits reflects the two possibilities implemented by historical implemen‐
172       tations when checking superuser access for X_OK.
173
174       New implementations are discouraged from returning X_OK unless at least
175       one execution permission bit is set.
176
177       The  purpose  of  the faccessat() function is to enable the checking of
178       the accessibility of files in directories other than the current  work‐
179       ing directory without exposure to race conditions. Any part of the path
180       of a file could be changed in parallel to a call to access(), resulting
181       in  unspecified  behavior.  By opening a file descriptor for the target
182       directory and using the faccessat() function it can be guaranteed  that
183       the  file  tested  for accessibility is located relative to the desired
184       directory.
185

FUTURE DIRECTIONS

187       None.
188

SEE ALSO

190       chmod(), fstatat()
191
192       The Base Definitions volume of POSIX.1‐2008, Section 4.4,  File  Access
193       Permissions, <fcntl.h>, <unistd.h>
194
196       Portions  of  this text are reprinted and reproduced in electronic form
197       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
198       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
199       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
200       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
201       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
202       event of any discrepancy between this version and the original IEEE and
203       The Open Group Standard, the original IEEE and The Open Group  Standard
204       is  the  referee document. The original Standard can be obtained online
205       at http://www.unix.org/online.html .
206
207       Any typographical or formatting errors that appear  in  this  page  are
208       most likely to have been introduced during the conversion of the source
209       files to man page format. To report such errors,  see  https://www.ker
210       nel.org/doc/man-pages/reporting_bugs.html .
211
212
213
214IEEE/The Open Group                  2013                           ACCESS(3P)
Impressum