xref: /csrg-svn/lib/libc/sys/access.2 (revision 66572)
161181Sbostic.\" Copyright (c) 1980, 1991, 1993
261181Sbostic.\"	The Regents of the University of California.  All rights reserved.
320056Smckusick.\"
447208Scael.\" %sccs.include.redist.man%
520056Smckusick.\"
6*66572Sbostic.\"     @(#)access.2	8.2 (Berkeley) 04/01/94
747208Scael.\"
847208Scael.Dd
947208Scael.Dt ACCESS 2
1047208Scael.Os BSD 4
1147208Scael.Sh NAME
1247208Scael.Nm access
1347208Scael.Nd check access permissions of a file or pathname
1447208Scael.Sh SYNOPSIS
1547208Scael.Fd #include <unistd.h>
1647208Scael.Ft int
1747208Scael.Fn access "const char *path" "int mode"
1847208Scael.Sh DESCRIPTION
1947208ScaelThe
2047208Scael.Fn access
2147208Scaelfunction checks the accessibility of the
2247208Scaelfile named by
2347208Scael.Fa path
2447208Scaelfor the access permissions indicated by
2547208Scael.Fa mode .
2647208ScaelThe value of
2747208Scael.Fa mode
2847208Scaelis the bitwise inclusive OR of the access permissions to be
2947208Scaelchecked
3047208Scael.Pf ( Dv R_OK
3147208Scaelfor read permission,
3247208Scael.Dv W_OK
3347208Scaelfor write permission and
3447208Scael.Dv X_OK
3547208Scaelfor execute/search permission) or the existence test,
3647208Scael.Dv F_OK .
3747208ScaelAll components of the pathname
3847208Scael.Fa path
3947208Scaelare checked for access permissions (including
4047208Scael.Dv F_OK ) .
4147208Scael.Pp
4247208ScaelThe real user ID is used in place of the effective user ID
4347208Scaeland the real group access list
4420057Smckusick(including the real group ID) are
4547208Scaelused in place of the effective ID for verifying permission.
4647208Scael.Pp
4747208ScaelEven if a process has appropriate privileges and indicates success for
4847208Scael.Dv X_OK ,
4947208Scaelthe file may not actually have execute permission bits set.
5047208ScaelLikewise for
5147208Scael.Dv R_OK
5247208Scaeland
5347208Scael.Dv W_OK .
5447208Scael.Sh RETURN VALUES
5520057SmckusickIf
5647208Scael.Fa path
5720057Smckusickcannot be found or if any of the desired access modes would
5847208Scaelnot be granted, then a -1 value is returned; otherwise
5920057Smckusicka 0 value is returned.
6047208Scael.Sh ERRORS
6147208ScaelAccess to the file is denied if:
6247208Scael.Bl -tag -width Er
6347208Scael.It Bq Er ENOTDIR
6420057SmckusickA component of the path prefix is not a directory.
6547208Scael.It Bq Er EINVAL
6621003SmckusickThe pathname contains a character with the high-order bit set.
6747208Scael.It Bq Er ENAMETOOLONG
6821003SmckusickA component of a pathname exceeded 255 characters,
6921003Smckusickor an entire path name exceeded 1023 characters.
7047208Scael.It Bq Er ENOENT
7124439SmckusickThe named file does not exist.
7247208Scael.It Bq Er ELOOP
7320057SmckusickToo many symbolic links were encountered in translating the pathname.
7447208Scael.It Bq Er EROFS
7520057SmckusickWrite access is requested for a file on a read-only file system.
7647208Scael.It Bq Er ETXTBSY
7720057SmckusickWrite access is requested for a pure procedure (shared text)
7847208Scaelfile presently being executed.
7947208Scael.It Bq Er EACCES
8020057SmckusickPermission bits of the file mode do not permit the requested
8128357Sanneaccess, or search permission is denied on a component of the
8220057Smckusickpath prefix.  The owner of a file has permission checked with
8320057Smckusickrespect to the ``owner'' read, write, and execute mode bits,
8420057Smckusickmembers of the file's group other than the owner have permission
8520057Smckusickchecked with respect to the ``group'' mode bits, and all
8620057Smckusickothers have permissions checked with respect to the ``other''
8720057Smckusickmode bits.
8847208Scael.It Bq Er EFAULT
8947208Scael.Fa Path
9020057Smckusickpoints outside the process's allocated address space.
9147208Scael.It Bq Er EIO
9224439SmckusickAn I/O error occurred while reading from or writing to the file system.
9347208Scael.El
9447208Scael.Sh SEE ALSO
9547208Scael.Xr chmod 2 ,
9647208Scael.Xr stat 2
9747208Scael.Sh STANDARDS
9847208Scael.Fn Access
9947208Scaelconforms to IEEE Std 1003.1-1988
10047208Scael.Pq Dq Tn POSIX .
10147208Scael.Sh CAVEAT
10247208Scael.Fn Access
10347208Scaelis a potential security hole and
10447208Scaelshould never be used.
105