1.\" Copyright (c) 1980, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)access.2 8.2 (Berkeley) 04/01/94 7.\" 8.Dd 9.Dt ACCESS 2 10.Os BSD 4 11.Sh NAME 12.Nm access 13.Nd check access permissions of a file or pathname 14.Sh SYNOPSIS 15.Fd #include <unistd.h> 16.Ft int 17.Fn access "const char *path" "int mode" 18.Sh DESCRIPTION 19The 20.Fn access 21function checks the accessibility of the 22file named by 23.Fa path 24for the access permissions indicated by 25.Fa mode . 26The value of 27.Fa mode 28is the bitwise inclusive OR of the access permissions to be 29checked 30.Pf ( Dv R_OK 31for read permission, 32.Dv W_OK 33for write permission and 34.Dv X_OK 35for execute/search permission) or the existence test, 36.Dv F_OK . 37All components of the pathname 38.Fa path 39are checked for access permissions (including 40.Dv F_OK ) . 41.Pp 42The real user ID is used in place of the effective user ID 43and the real group access list 44(including the real group ID) are 45used in place of the effective ID for verifying permission. 46.Pp 47Even if a process has appropriate privileges and indicates success for 48.Dv X_OK , 49the file may not actually have execute permission bits set. 50Likewise for 51.Dv R_OK 52and 53.Dv W_OK . 54.Sh RETURN VALUES 55If 56.Fa path 57cannot be found or if any of the desired access modes would 58not be granted, then a -1 value is returned; otherwise 59a 0 value is returned. 60.Sh ERRORS 61Access to the file is denied if: 62.Bl -tag -width Er 63.It Bq Er ENOTDIR 64A component of the path prefix is not a directory. 65.It Bq Er EINVAL 66The pathname contains a character with the high-order bit set. 67.It Bq Er ENAMETOOLONG 68A component of a pathname exceeded 255 characters, 69or an entire path name exceeded 1023 characters. 70.It Bq Er ENOENT 71The named file does not exist. 72.It Bq Er ELOOP 73Too many symbolic links were encountered in translating the pathname. 74.It Bq Er EROFS 75Write access is requested for a file on a read-only file system. 76.It Bq Er ETXTBSY 77Write access is requested for a pure procedure (shared text) 78file presently being executed. 79.It Bq Er EACCES 80Permission bits of the file mode do not permit the requested 81access, or search permission is denied on a component of the 82path prefix. The owner of a file has permission checked with 83respect to the ``owner'' read, write, and execute mode bits, 84members of the file's group other than the owner have permission 85checked with respect to the ``group'' mode bits, and all 86others have permissions checked with respect to the ``other'' 87mode bits. 88.It Bq Er EFAULT 89.Fa Path 90points outside the process's allocated address space. 91.It Bq Er EIO 92An I/O error occurred while reading from or writing to the file system. 93.El 94.Sh SEE ALSO 95.Xr chmod 2 , 96.Xr stat 2 97.Sh STANDARDS 98.Fn Access 99conforms to IEEE Std 1003.1-1988 100.Pq Dq Tn POSIX . 101.Sh CAVEAT 102.Fn Access 103is a potential security hole and 104should never be used. 105