xref: /openbsd-src/lib/libc/sys/access.2 (revision 62a742911104f98b9185b2c6b6007d9b1c36396c)
1.\"	$OpenBSD: access.2,v 1.4 1999/02/27 21:56:05 deraadt 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 BSD 4
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
51file named by
52.Fa path
53for the access permissions indicated by
54.Fa mode .
55The value of
56.Fa mode
57is the bitwise inclusive OR of the access permissions to be
58checked
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
87not be granted, then a -1 value is returned; otherwise
88a 0 value is returned.
89.Sh ERRORS
90Access to the file is denied if:
91.Bl -tag -width Er
92.It Bq Er ENOTDIR
93A component of the path prefix is not a directory.
94.It Bq Er ENAMETOOLONG
95A component of a pathname exceeded
96.Dv {NAME_MAX}
97characters, or an entire path name exceeded
98.Dv {PATH_MAX}
99characters.
100.It Bq Er ENOENT
101The named file does not exist.
102.It Bq Er ELOOP
103Too many symbolic links were encountered in translating the pathname.
104.It Bq Er EROFS
105Write access is requested for a file on a read-only file system.
106.It Bq Er ETXTBSY
107Write access is requested for a pure procedure (shared text)
108file presently being executed.
109.It Bq Er EACCES
110Permission bits of the file mode do not permit the requested
111access, or search permission is denied on a component of the
112path prefix.  The owner of a file has permission checked with
113respect to the ``owner'' read, write, and execute mode bits,
114members of the file's group other than the owner have permission
115checked with respect to the ``group'' mode bits, and all
116others have permissions checked with respect to the ``other''
117mode bits.
118.It Bq Er EFAULT
119.Fa path
120points outside the process's allocated address space.
121.It Bq Er EIO
122An I/O error occurred while reading from or writing to the file system.
123.It Bq Er EINVAL
124An invalid value was specified for
125.Ar mode .
126.El
127.Sh SEE ALSO
128.Xr chmod 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