Checking access permissions of a file or directoryΒΆ

access()

Check access permissions of a file or directory


SYNTAX

access(pathname, mode)

Checks the existence or access permission of a file or directory.

pathname

The path of the file or directory to be checked.

mode

The type of check to be made. The possible values for mode are defined in the standard include file $SCULPTOR/include/files.h, and are as follows:

TEST_EXISTS

Check if the file exists

TEST_CANEXEC

Check if current user has execute permission

TEST_CANREAD

Check if current user has read permission

TEST_CANWRITE

Check if current user has write permission

The mode TEST_EXISTS must be tested on its own; the other modes may be combined using the | operator.

The function returns zero if the file exists or if the current user has the specified permission(s); otherwise it returns -1 and assigns the operating system error code to sys.Errno.


EXAMPLES

if (access(tmp.FilePath, TEST_EXISTS) = 0) {
     prompt "File already exists - over-write?" \
     button = "  YES  " \
     button = "  NO   ",  FINISH


if (access("/logdir", TEST_CANEXEC | TEST_CANREAD | TEST_CANWRI | TE) <> 0) {
     info "Permission denied"
}

RELATED TOPICS

File and directory handling functions

chmod()

fileinfo()