FAT | RFS | XFS | ZFS

access()

PROTOTYPE

#include <posix.h>

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

DESCRIPTION

access() checks accessibility of the file specified by path. Paths are absolute if starting with ‘/’, otherwise they are relative to the CWD. amode specifies the access permissions to be checked and should be a bitwise OR of the following values:

  • R_OK - test if file is readable
  • W_OK - test if file is writable
  • X_OK - test if file is executable
  • F_OK - test if file exists

The caller needs execute access to every directory in the path prefix.

If successful, access() returns 0. Otherwise, it sets errno and returns -1.

ERROR CODES

EACCES No execute access to a directory in the path prefix or an access specified by amode is denied.
EFAULT path equals NULL.
EINVAL The value of amode is invalid.
ENAMETOOLONG A name in path exceeds the effective maximum file name length.
ENOENT path is the empty string or includes a file that was not found.
ENOTDIR One of the non-leaf path components is not a directory.
EROFS Write access requested for file on read-only volume.

EXAMPLE

/*---------------------------------------------------------------*/
/* Check if the current working directory can be read.           */
/*---------------------------------------------------------------*/
if (access(".", R_OK))
  printf("Can't call opendir() on this directory");