make it possible to compile new versions of db that load against
[unix-history] / usr / src / lib / libc / sys / access.2
CommitLineData
aaea5b2e
KB
1.\" Copyright (c) 1980, 1991, 1993
2.\" The Regents of the University of California. All rights reserved.
efb227b8 3.\"
931b8415 4.\" %sccs.include.redist.man%
efb227b8 5.\"
aaea5b2e 6.\" @(#)access.2 8.1 (Berkeley) %G%
931b8415
CL
7.\"
8.Dd
9.Dt ACCESS 2
10.Os BSD 4
11.Sh NAME
12.Nm access
13.Nd check access permissions of a file or pathname
14.Sh SYNOPSIS
15.Fd #include <unistd.h>
16.Ft int
17.Fn access "const char *path" "int mode"
18.Sh DESCRIPTION
19The
20.Fn access
21function checks the accessibility of the
22file named by
23.Fa path
24for the access permissions indicated by
25.Fa mode .
26The value of
27.Fa mode
28is the bitwise inclusive OR of the access permissions to be
29checked
30.Pf ( Dv R_OK
31for read permission,
32.Dv W_OK
33for write permission and
34.Dv X_OK
35for execute/search permission) or the existence test,
36.Dv F_OK .
37All components of the pathname
38.Fa path
39are checked for access permissions (including
40.Dv F_OK ) .
41.Pp
42The real user ID is used in place of the effective user ID
43and the real group access list
c07fe3ba 44(including the real group ID) are
931b8415
CL
45used in place of the effective ID for verifying permission.
46.Pp
47Even if a process has appropriate privileges and indicates success for
48.Dv X_OK ,
49the file may not actually have execute permission bits set.
50Likewise for
51.Dv R_OK
52and
53.Dv W_OK .
54.Sh RETURN VALUES
c07fe3ba 55If
931b8415 56.Fa path
c07fe3ba 57cannot be found or if any of the desired access modes would
931b8415 58not be granted, then a -1 value is returned; otherwise
c07fe3ba 59a 0 value is returned.
931b8415
CL
60.Sh ERRORS
61Access to the file is denied if:
62.Bl -tag -width Er
63.It Bq Er ENOTDIR
c07fe3ba 64A component of the path prefix is not a directory.
931b8415 65.It Bq Er EINVAL
b5984ffe 66The pathname contains a character with the high-order bit set.
931b8415 67.It Bq Er ENAMETOOLONG
b5984ffe
KM
68A component of a pathname exceeded 255 characters,
69or an entire path name exceeded 1023 characters.
931b8415 70.It Bq Er ENOENT
fd690c8b 71The named file does not exist.
931b8415 72.It Bq Er EACCES
b5984ffe 73Search permission is denied for a component of the path prefix.
931b8415 74.It Bq Er ELOOP
c07fe3ba 75Too many symbolic links were encountered in translating the pathname.
931b8415 76.It Bq Er EROFS
c07fe3ba 77Write access is requested for a file on a read-only file system.
931b8415 78.It Bq Er ETXTBSY
c07fe3ba 79Write access is requested for a pure procedure (shared text)
931b8415
CL
80file presently being executed.
81.It Bq Er EACCES
c07fe3ba 82Permission bits of the file mode do not permit the requested
26ce5037 83access, or search permission is denied on a component of the
c07fe3ba
KM
84path prefix. The owner of a file has permission checked with
85respect to the ``owner'' read, write, and execute mode bits,
86members of the file's group other than the owner have permission
87checked with respect to the ``group'' mode bits, and all
88others have permissions checked with respect to the ``other''
89mode bits.
931b8415
CL
90.It Bq Er EFAULT
91.Fa Path
c07fe3ba 92points outside the process's allocated address space.
931b8415 93.It Bq Er EIO
fd690c8b 94An I/O error occurred while reading from or writing to the file system.
931b8415
CL
95.El
96.Sh SEE ALSO
97.Xr chmod 2 ,
98.Xr stat 2
99.Sh STANDARDS
100.Fn Access
101conforms to IEEE Std 1003.1-1988
102.Pq Dq Tn POSIX .
103.Sh CAVEAT
104.Fn Access
105is a potential security hole and
106should never be used.