access()

determine the accessibility of a file 

Function


SYNOPSIS

#include <unistd.h>

int access(const char *pathname, int amode);


DESCRIPTION

The access() function tests a file, pathname, to determine its accessibility according to the file access permissions indicated by amode. This function uses the real user ID instead of the effective user ID and the real group ID instead of the effective group ID.

The value of amode is either the bitwise inclusive-OR of the following access permissions to be checked, or is F_OK, which checks for the existence of the file:

R_OK 

Tests for Read permission

W_OK 

Tests for Write permission

X_OK 

Tests for Execute or Search permissions.

D_OK 

Tests for Delete permission

P_OK 

Tests for Change Permission permission.

O_OK 

Tests for Take Ownership permission.

If any access permissions are checked, each is checked individually, in the order listed earlier, for other, then group, then owner.


PARAMETERS

pathname 

A pointer to the file to be checked for access.

amode 

A bitwise-OR value that specifies the type of access to check for.


RETURN VALUES

If the requested access is permitted, access() returns a value of zero. On failure, it returns a value of -1 and sets errno to one of the following values:

EACCES 

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

EFAULT 

The pathname parameter is not a valid pointer.

EINTR 

A signal interrupted the call.

EINVAL 

An invalid value was specified for amode.

ENAMETOOLONG 

The length of pathname exceeds PATH_MAX or the length of a pathname component exceeds NAME_MAX.

ENOENT 

pathname points to an empty string or to the name of a file that does not exist.

ENOTDIR 

A component of the pathname prefix is not a directory.

EROFS 

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


CONFORMANCE

POSIX.1 (1996), with exceptions.


MULTITHREAD SAFETY LEVEL

Async-signal-safe.


PORTING ISSUES

In file systems other than NTFS, access permissions are limited to DOS attribute information. Directories always have read and write access. Files have either read-only or read, write, execute access. With NTFS file systems, file access is fully implemented.

On NTFS, the DACL in the file descriptor determines the access permissions of a file. However, the DOS file attribute for read-only overrides the DACL -- if the read-only attribute is set, the write access is denied, even if otherwise allowed by the DACL. Refer to File Security in the Windows Concepts chapter of the PTC MKS Toolkit UNIX to Windows Porting Guide for more information

If the _NutConf() parameter _NC_SET_SUFFIXED_SEARCHING has been set, if the specified file cannot be located when searching for X_OK access, a second check is made for the file with a .exe suffix appended.

File names are treated as multibyte sequences and are converted to Unicode (UTF-16) before passing to Win32. The conversion is either performed based on the current thread locale, set using uselocale() or the process locale as set by a call to setlocale(), and overridden by _NutConf() _NC_SET_ANSI_LOCALE and _NC_SET_UTF8_LOCALE options. Under all other conditions, the multibyte sequences are considered to be from the ANSI code page for the current windows system locale.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
_NutConf(), chmod(), fstat(), stat(), xlocale()

Miscellaneous:
struct stat


PTC MKS Toolkit 10.4 Documentation Build 39.