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