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