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