Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

access, faccessat - check access permissions for file

&pagelevel(4)&pagelevel

Syntax

#include <unistd.h>

int access(const char *path, int amode);
int faccessat(int fd, const char *path, int amode, int flag);



Description

access() checks the file named by the path argument for accessibility according to the bitpattern contained in amode, using the real user ID in place of the effective user ID and the
real group ID in place of the effective group

The following symbolic constants can be specified for amode:

R_OK

W_OK

X_OK

F_OK

to check for read permission

to check for write permission

to check for execute (search) permission

to check if the file exists

The value of amode is either the bit-wise inclusive OR of the access permissions to be checked (R_OK, W_OK, X_OK) or the existence test, F_OK (see also unistd.h).

Extension
Other values for amode may be permitted in addition to those listed above (e.g. if a system has extended access controls). (End)

A process with appropriate privileges may search a file even if none of the execute file permission bits are set, but success will not indicated when checking for X_OK.

The faccessat() function is equivalent to the access() function except when the path parameter specifies a relative path. In this case the file whose access rights are to be checked is not searched for in the current directory, but in the directory connected with the file descriptor fd. If the file descriptor was opened without O_SEARCH, the function checks whether a search is permitted in the connected file descriptor with the authorizations applicable for the directory. If the file descriptor was opened with O_SEARCH, the check is not performed.

In the flag parameter, the value AT_EACCESS, which is defined in the fnctl.h header, can be transferred. In this case the effective user and group numbers are used for the check instead of the real ones.

When the value AT_FDCWD is transferred to the faccessat() function for the fd parameter, the current directory is used.

Return val.

0

The requested access is permitted.


-1

The requested access is not permitted; errno is set to indicate the error.

Errors

access() and faccessat() will fail if:


EACCES

Permission bits of the file mode do not permit the requested access, orsearch permission is denied on a component of the path prefix.


Extension


EFAULT

path is an invalid address.


EINTR

A signal was caught during the access() system call. (End)


ELOOP

The maximum number of symbolic links in path was exceeded (or the maximum number of symbolic links is defined by MAXSYMLINKS in the header file sys/param.h).


ENAMETOOLONG



The length of the path argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.


ENOENT

The path argument points to a non-existent file or to an empty string.


ENOTDIR

A component of the path prefix is not a directory.


EROFS

Write access is requested for a file on a read-only file system.


In addition, faccessat() fails if the following applies:


EACCES

The fd parameter was not opened with O_SEARCH, and the authorizations applicable for the directory do not permit the directory to be searched.


EBADF

The path parameter does not specify an absolute pathname, and the fd parameter does not have the value AT_FDCWD, nor does it contain a valid file descriptor opened for reading or searching.


ENOTDIR

The path parameter does not specify an absolute pathname, and the file descriptor fd is not connected with a directory.


EINVAL

The value of the flag parameter is invalid.


Extension

 

EBADF

An attempt was made to access a BS2000 file.

Note

access() and faccessat() are executed for POSIX files only.

See also

chmod(), stat(), fcntl.h, unistd.h.