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

NAME

6       access - determine accessibility of a file
7

SYNOPSIS

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

DESCRIPTION

15       The  access()  function  shall  check  the  file  named by the pathname
16       pointed to by the path argument for accessibility according to the  bit
17       pattern  contained  in  amode,  using  the real user ID in place of the
18       effective user ID and the real group ID in place of the effective group
19       ID.
20
21       The  value  of  amode  is either the bitwise-inclusive OR of the access
22       permissions to be checked (R_OK, W_OK,  X_OK)  or  the  existence  test
23       (F_OK).
24
25       If  any access permissions are checked, each shall be checked individu‐
26       ally,   as   described   in   the   Base    Definitions    volume    of
27       IEEE Std 1003.1-2001, Chapter 3, Definitions. If the process has appro‐
28       priate privileges, an implementation may indicate success for X_OK even
29       if none of the execute file permission bits are set.
30

RETURN VALUE

32       If  the  requested  access  is  permitted,  access() succeeds and shall
33       return 0; otherwise, -1 shall be returned and errno  shall  be  set  to
34       indicate the error.
35

ERRORS

37       The access() function shall fail if:
38
39       EACCES Permission  bits  of  the  file mode do not permit the requested
40              access, or search permission is denied on  a  component  of  the
41              path prefix.
42
43       ELOOP  A loop exists in symbolic links encountered during resolution of
44              the path argument.
45
46       ENAMETOOLONG
47              The length of the path argument exceeds {PATH_MAX} or a pathname
48              component is longer than {NAME_MAX}.
49
50       ENOENT A component of path does not name an existing file or path is an
51              empty string.
52
53       ENOTDIR
54              A component of the path prefix is not a directory.
55
56       EROFS  Write access is requested for a file on a read-only file system.
57
58
59       The access() function may fail if:
60
61       EINVAL The value of the amode argument is invalid.
62
63       ELOOP  More than {SYMLOOP_MAX} symbolic links were  encountered  during
64              resolution of the path argument.
65
66       ENAMETOOLONG
67              As a result of encountering a symbolic link in resolution of the
68              path argument, the length of  the  substituted  pathname  string
69              exceeded {PATH_MAX}.
70
71       ETXTBSY
72              Write  access  is  requested  for a pure procedure (shared text)
73              file that is being executed.
74
75
76       The following sections are informative.
77

EXAMPLES

79   Testing for the Existence of a File
80       The following example tests whether a file named myfile exists  in  the
81       /tmp directory.
82
83
84              #include <unistd.h>
85              ...
86              int result;
87              const char *filename = "/tmp/myfile";
88
89
90              result = access (filename, F_OK);
91

APPLICATION USAGE

93       Additional  values  of amode other than the set defined in the descrip‐
94       tion may be valid; for example, if a system has  extended  access  con‐
95       trols.
96

RATIONALE

98       In  early  proposals, some inadequacies in the access() function led to
99       the creation of an eaccess() function because:
100
101        1. Historical implementations of access() do not test file access cor‐
102           rectly  when the process' real user ID is superuser. In particular,
103           they always return zero when testing  execute  permissions  without
104           regard to whether the file is executable.
105
106        2. The  superuser  has  complete access to all files on a system. As a
107           consequence, programs started by the superuser and switched to  the
108           effective  user  ID  with  lesser privileges cannot use access() to
109           test their file access permissions.
110
111       However, the historical model of eaccess()  does  not  resolve  problem
112       (1),  so  this  volume  of  IEEE Std 1003.1-2001 now allows access() to
113       behave in the desired way because  several  implementations  have  cor‐
114       rected  the problem. It was also argued that problem (2) is more easily
115       solved by using open(), chdir(), or one of the exec functions as appro‐
116       priate and responding to the error, rather than creating a new function
117       that would not be as reliable. Therefore, eaccess() is not included  in
118       this volume of IEEE Std 1003.1-2001.
119
120       The  sentence  concerning appropriate privileges and execute permission
121       bits reflects the two possibilities implemented by historical implemen‐
122       tations when checking superuser access for X_OK.
123
124       New implementations are discouraged from returning X_OK unless at least
125       one execution permission bit is set.
126

FUTURE DIRECTIONS

128       None.
129

SEE ALSO

131       chmod() , stat() , the Base Definitions volume of IEEE Std 1003.1-2001,
132       <unistd.h>
133
135       Portions  of  this text are reprinted and reproduced in electronic form
136       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
137       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
138       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
139       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
140       event of any discrepancy between this version and the original IEEE and
141       The  Open Group Standard, the original IEEE and The Open Group Standard
142       is the referee document. The original Standard can be  obtained  online
143       at http://www.opengroup.org/unix/online.html .
144
145
146
147IEEE/The Open Group                  2003                            ACCESS(P)
Impressum