update error return values
[unix-history] / usr / src / lib / libc / sys / 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.\"
1db29d5f 5.\" @(#)access.2 6.2 (Berkeley) %G%
efb227b8 6.\"
d31f1e1b 7.TH ACCESS 2 ""
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
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
73[ENOENT]
74The argument path name was too long.
75.TP 15
76[ENOENT]
77Read, write, or execute (search) permission is requested for a null
78path name or the named file does not exist.
79.TP 15
80[EPERM]
81The argument contains a byte with the high-order bit set.
82.TP 15
83[ELOOP]
84Too many symbolic links were encountered in translating the pathname.
85.TP 15
86[EROFS]
87Write access is requested for a file on a read-only file system.
88.TP 15
89[ETXTBSY]
90Write access is requested for a pure procedure (shared text)
91file that is being executed.
92.TP 15
93[EACCES]
94Permission bits of the file mode do not permit the requested
95access; or search permission is denied on a component of the
96path prefix. The owner of a file has permission checked with
97respect to the ``owner'' read, write, and execute mode bits,
98members of the file's group other than the owner have permission
99checked with respect to the ``group'' mode bits, and all
100others have permissions checked with respect to the ``other''
101mode bits.
102.TP 15
103[EFAULT]
104.I Path
105points outside the process's allocated address space.
106.SH "SEE ALSO
107chmod(2), stat(2)