BSD 4_3 release
[unix-history] / usr / man / man2 / access.2
CommitLineData
efb227b8
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
95f51977 5.\" @(#)access.2 6.5 (Berkeley) 5/22/86
efb227b8 6.\"
95f51977 7.TH ACCESS 2 "May 22, 1986"
efb227b8
KM
8.UC 4
9.SH NAME
10access \- determine accessibility of file
11.SH SYNOPSIS
12.nf
c07fe3ba
KM
13.ft B
14#include <sys/file.h>
15.PP
16.ft B
17.ta 1.25i 1.6i
18#define R_OK 4 /* test for read permission */
19#define W_OK 2 /* test for write permission */
20#define X_OK 1 /* test for execute (search) permission */
21#define F_OK 0 /* test for presence of file */
22.PP
23.ft B
24accessible = access(path, mode)
25int accessible;
26char *path;
27int mode;
28.ft R
efb227b8
KM
29.fi
30.SH DESCRIPTION
31.I Access
32checks the given
33file
c07fe3ba 34.I path
efb227b8 35for accessibility according to
c07fe3ba
KM
36.IR mode ,
37which is an inclusive or of the bits
38R_OK,
39W_OK
40and
41X_OK.
42Specifying
43.I mode
26ce5037 44as F_OK (i.e., 0)
efb227b8
KM
45tests whether the directories leading to the file can be
46searched and the file exists.
47.PP
c07fe3ba
KM
48The real user ID and the group access list
49(including the real group ID) are
50used in verifying permission, so this call
51is useful to set-UID programs.
efb227b8 52.PP
c07fe3ba
KM
53Notice that only access bits are checked.
54A directory may be indicated as writable by
55.IR access ,
efb227b8
KM
56but an attempt to open it for writing will fail
57(although files may be created there);
58a file may look executable, but
c07fe3ba 59.I execve
efb227b8 60will fail unless it is in proper format.
c07fe3ba
KM
61.SH "RETURN VALUE
62If
63.I path
64cannot be found or if any of the desired access modes would
65not be granted, then a \-1 value is returned; otherwise
66a 0 value is returned.
67.SH "ERRORS
68Access to the file is denied if one or more of the following are true:
69.TP 15
70[ENOTDIR]
71A component of the path prefix is not a directory.
72.TP 15
b5984ffe
KM
73[EINVAL]
74The pathname contains a character with the high-order bit set.
75.TP 15
76[ENAMETOOLONG]
77A component of a pathname exceeded 255 characters,
78or an entire path name exceeded 1023 characters.
c07fe3ba
KM
79.TP 15
80[ENOENT]
fd690c8b 81The named file does not exist.
c07fe3ba 82.TP 15
b5984ffe
KM
83[EACCES]
84Search permission is denied for a component of the path prefix.
c07fe3ba
KM
85.TP 15
86[ELOOP]
87Too many symbolic links were encountered in translating the pathname.
88.TP 15
89[EROFS]
90Write access is requested for a file on a read-only file system.
91.TP 15
92[ETXTBSY]
93Write access is requested for a pure procedure (shared text)
94file that is being executed.
95.TP 15
96[EACCES]
97Permission bits of the file mode do not permit the requested
26ce5037 98access, or search permission is denied on a component of the
c07fe3ba
KM
99path prefix. The owner of a file has permission checked with
100respect to the ``owner'' read, write, and execute mode bits,
101members of the file's group other than the owner have permission
102checked with respect to the ``group'' mode bits, and all
103others have permissions checked with respect to the ``other''
104mode bits.
105.TP 15
106[EFAULT]
107.I Path
108points outside the process's allocated address space.
fd690c8b
KM
109.TP 15
110[EIO]
111An I/O error occurred while reading from or writing to the file system.
c07fe3ba
KM
112.SH "SEE ALSO
113chmod(2), stat(2)