xref: /netbsd-src/lib/libc/sys/access.2 (revision 38023541164cff097d5fadec63134189b1453b8c)
1.\" Copyright (c) 1980, 1991 Regents of the University of California.
2.\" 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.\"     from: @(#)access.2	6.7 (Berkeley) 3/10/91
33.\"	$Id: access.2,v 1.3 1993/11/25 00:38:20 jtc Exp $
34.\"
35.Dd March 10, 1991
36.Dt ACCESS 2
37.Os BSD 4
38.Sh NAME
39.Nm access
40.Nd check access permissions of a file or pathname
41.Sh SYNOPSIS
42.Fd #include <unistd.h>
43.Ft int
44.Fn access "const char *path" "int mode"
45.Sh DESCRIPTION
46The
47.Fn access
48function checks the accessibility of the
49file named by
50.Fa path
51for the access permissions indicated by
52.Fa mode .
53The value of
54.Fa mode
55is the bitwise inclusive OR of the access permissions to be
56checked
57.Pf ( Dv R_OK
58for read permission,
59.Dv W_OK
60for write permission and
61.Dv X_OK
62for execute/search permission) or the existence test,
63.Dv F_OK .
64All components of the pathname
65.Fa path
66are checked for access permissions (including
67.Dv F_OK ) .
68.Pp
69The real user ID is used in place of the effective user ID
70and the real group access list
71(including the real group ID) are
72used in place of the effective ID for verifying permission.
73.Pp
74Even if a process has appropriate privileges and indicates success for
75.Dv X_OK ,
76the file may not actually have execute permission bits set.
77Likewise for
78.Dv R_OK
79and
80.Dv W_OK .
81.Sh RETURN VALUES
82If
83.Fa path
84cannot be found or if any of the desired access modes would
85not be granted, then a -1 value is returned; otherwise
86a 0 value is returned.
87.Sh ERRORS
88Access to the file is denied if:
89.Bl -tag -width Er
90.It Bq Er ENOTDIR
91A component of the path prefix is not a directory.
92.It Bq Er EINVAL
93The pathname contains a character with the high-order bit set.
94.It Bq Er ENAMETOOLONG
95A component of a pathname exceeded 255 characters,
96or an entire path name exceeded 1023 characters.
97.It Bq Er ENOENT
98The named file does not exist.
99.It Bq Er EACCES
100Search permission is denied for a component of the path prefix.
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
110access, or search permission is denied on a component of the
111path prefix.  The owner of a file has permission checked with
112respect to the ``owner'' read, write, and execute mode bits,
113members of the file's group other than the owner have permission
114checked with respect to the ``group'' mode bits, and all
115others have permissions checked with respect to the ``other''
116mode bits.
117.It Bq Er EFAULT
118.Fa Path
119points outside the process's allocated address space.
120.It Bq Er EIO
121An I/O error occurred while reading from or writing to the file system.
122.El
123.Sh SEE ALSO
124.Xr chmod 2 ,
125.Xr stat 2
126.Sh STANDARDS
127The
128.Fn access
129function conforms to
130.St -p1003.1-88 .
131.Sh CAVEAT
132.Fn Access
133is a potential security hole and
134should never be used.
135