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