1.\" Copyright (c) 1980, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)access.2 8.2 (Berkeley) 4/1/94 33.\" 34.Dd April 1, 1994 35.Dt ACCESS 2 36.Os BSD 4 37.Sh NAME 38.Nm access 39.Nd check access permissions of a file or pathname 40.Sh SYNOPSIS 41.Fd #include <unistd.h> 42.Ft int 43.Fn access "const char *path" "int mode" 44.Sh DESCRIPTION 45The 46.Fn access 47function checks the accessibility of the 48file named by 49.Fa path 50for the access permissions indicated by 51.Fa mode . 52The value of 53.Fa mode 54is the bitwise inclusive OR of the access permissions to be 55checked 56.Pf ( Dv R_OK 57for read permission, 58.Dv W_OK 59for write permission and 60.Dv X_OK 61for execute/search permission) or the existence test, 62.Dv F_OK . 63All components of the pathname 64.Fa path 65are checked for access permissions (including 66.Dv F_OK ) . 67.Pp 68The real user ID is used in place of the effective user ID 69and the real group access list 70(including the real group ID) are 71used in place of the effective ID for verifying permission. 72.Pp 73Even if a process has appropriate privileges and indicates success for 74.Dv X_OK , 75the file may not actually have execute permission bits set. 76Likewise for 77.Dv R_OK 78and 79.Dv W_OK . 80.Sh RETURN VALUES 81If 82.Fa path 83cannot be found or if any of the desired access modes would 84not be granted, then a -1 value is returned; otherwise 85a 0 value is returned. 86.Sh ERRORS 87Access to the file is denied if: 88.Bl -tag -width Er 89.It Bq Er ENOTDIR 90A component of the path prefix is not a directory. 91.It Bq Er EINVAL 92The pathname contains a character with the high-order bit set. 93.It Bq Er ENAMETOOLONG 94A component of a pathname exceeded 255 characters, 95or an entire path name exceeded 1023 characters. 96.It Bq Er ENOENT 97The named file does not exist. 98.It Bq Er ELOOP 99Too many symbolic links were encountered in translating the pathname. 100.It Bq Er EROFS 101Write access is requested for a file on a read-only file system. 102.It Bq Er ETXTBSY 103Write access is requested for a pure procedure (shared text) 104file presently being executed. 105.It Bq Er EACCES 106Permission bits of the file mode do not permit the requested 107access, or search permission is denied on a component of the 108path prefix. The owner of a file has permission checked with 109respect to the ``owner'' read, write, and execute mode bits, 110members of the file's group other than the owner have permission 111checked with respect to the ``group'' mode bits, and all 112others have permissions checked with respect to the ``other'' 113mode bits. 114.It Bq Er EFAULT 115.Fa Path 116points outside the process's allocated address space. 117.It Bq Er EIO 118An I/O error occurred while reading from or writing to the file system. 119.El 120.Sh SEE ALSO 121.Xr chmod 2 , 122.Xr stat 2 123.Sh STANDARDS 124.Fn Access 125conforms to IEEE Std 1003.1-1988 126.Pq Dq Tn POSIX . 127.Sh CAVEAT 128.Fn Access 129is a potential security hole and 130should never be used. 131