2 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/.
6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text
7 .\" are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical
8 .\" and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
9 .\" This notice shall appear on any product containing this material.
10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
11 .\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with
12 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 .TH ACCESS 2 "Jun 16, 2009"
15 access, faccessat \- determine accessibility of a file
20 #include <sys/fcntl.h>
22 \fBint\fR \fBaccess\fR(\fBconst char *\fR\fIpath\fR, \fBint\fR \fIamode\fR);
27 \fBint\fR \fBfaccessat\fR(\fBint\fR \fIfd\fR, \fBconst char *\fR\fIpath\fR, \fBint\fR \fIamode\fR, \fBint\fR \fIflag\fR);
33 The \fBaccess()\fR function checks the file named by the pathname pointed to by
34 the \fIpath\fR argument for accessibility according to the bit pattern
35 contained in \fIamode\fR, using the real user \fBID\fR in place of the
36 effective user \fBID\fR and the real group \fBID\fR in place of the effective
37 group ID. This allows a setuid process to verify that the user running it would
38 have had permission to access this file.
41 The value of \fIamode\fR is either the bitwise inclusive \fBOR\fR of the access
42 permissions to be checked (\fBR_OK\fR, \fBW_OK\fR, \fBX_OK\fR) or the existence
46 These constants are defined in <\fBunistd.h\fR> as follows:
53 Test for read permission.
62 Test for write permission.
71 Test for execute or search permission.
80 Check existence of file
85 See \fBIntro\fR(2) for additional information about "File Access Permission".
88 If any access permissions are to be checked, each will be checked individually,
89 as described in \fBIntro\fR(2). If the process has appropriate privileges, an
90 implementation may indicate success for \fBX_OK\fR even if none of the execute
91 file permission bits are set.
94 The \fBfaccessat()\fR function is equivalent to the \fBaccess()\fR function,
95 except in the case where \fIpath\fR specifies a relative path. In this case the
96 file whose accessibility is to be determined is located relative to the
97 directory associated with the file descriptor \fIfd\fR instead of the current
101 If \fBfaccessat()\fR is passed in the \fIfd\fR parameter the special value
102 \fBAT_FDCWD\fR, defined in \fB<fcntl.h>\fR, the current working directory is
103 used and the behavior is identical to a call to \fBaccess()\fR.
106 Values for \fIflag\fR are constructed by a bitwise-inclusive OR of flags from
107 the following list, defined in \fB<fcntl.h>\fR:
111 \fB\fBAT_EACCESS\fR\fR
114 The checks for accessibility are performed using the effective user and group
115 IDs instead of the real user and group ID as required in a call to
122 If the requested access is permitted, \fBaccess()\fR and
123 \fBfaccessat()\fRsucceed and return \fB0\fR. Otherwise, \fB\(mi1\fR is returned
124 and \fBerrno\fR is set to indicate the error.
128 The \fBaccess()\fR and \fBfaccessat()\fR functions will fail if:
135 Permission bits of the file mode do not permit the requested access, or search
136 permission is denied on a component of the path prefix.
145 The \fIpath\fR argument points to an illegal address.
154 A signal was caught during the \fBaccess()\fR function.
163 Too many symbolic links were encountered in resolving \fIpath\fR, or loop
164 exists in symbolic links encountered during resolution of the \fIpath\fR
171 \fB\fBENAMETOOLONG\fR\fR
174 The length of the \fIpath\fR argument exceeds {\fBPATH_MAX\fR}, or a pathname
175 component is longer than {\fBNAME_MAX\fR} while \fB_POSIX_NO_TRUNC\fR is in
185 A component of \fIpath\fR does not name an existing file or \fIpath\fR is an
195 The \fIpath\fR argument points to a remote machine and the link to that machine
205 A component of the path prefix is not a directory.
214 The \fIpath\fR argument points to a character or block device special file and
215 the corresponding device has been retired by the fault management framework.
224 Write access is requested for a file on a read-only file system.
229 The \fBfaccessat()\fR function will fail if:
236 The \fIpath\fR argument does not specify an absolute path and the \fIfd\fR
237 argument is neither \fBAT_FDCWD\fR nor a valid file descriptor open for reading
243 The \fBaccess()\fR and \fBfaccessat()\fR functions may fail if:
250 The value of the \fIamode\fR argument is invalid.
256 \fB\fBENAMETOOLONG\fR\fR
259 Pathname resolution of a symbolic link produced an intermediate result whose
260 length exceeds {\fBPATH_MAX\fR}.
269 Write access is requested for a pure procedure (shared text) file that is being
275 The \fBfaccessat()\fR function may fail if:
282 The value of the \fIflag\fR argument is not valid.
291 The \fIpath\fR argument is not an absolute path and \fIfd\fR is neither
292 \fBAT_FDCWD\fR nor a file descriptor associated with a directory.
298 Additional values of \fIamode\fR other than the set defined in the description
299 might be valid, for example, if a system has extended access controls.
302 The purpose of the \fBfaccessat()\fR function is to enable the checking of the
303 accessibility of files in directories other than the current working directory
304 without exposure to race conditions. Any part of the path of a file could be
305 changed in parallel to a call to \fBaccess()\fR, resulting in unspecified
306 behavior. By opening a file descriptor for the target directory and using the
307 \fBfaccessat()\fR function, it can be guaranteed that the file tested for
308 accessibility is located relative to the desired directory.
312 See \fBattributes\fR(5) for descriptions of the following attributes:
320 ATTRIBUTE TYPE ATTRIBUTE VALUE
322 Interface Stability Committed
324 MT-Level Async-Signal-Safe
331 For \fBaccess()\fR, see \fBstandards\fR(5).
335 \fBIntro\fR(2), \fBchmod\fR(2), \fBstat\fR(2), \fBattributes\fR(5),