access
access — checks a file for various permissions.
Syntax
access (filename, mode)
Arguments
- filename
- The name of a file on
disk.
- mode
- The file mode to be tested. The legal
modes are discussed below.
Returns
Zero is returned if the access mode is
valid, otherwise -1 is returned and the errno is set.
Description
This function checks a file for the following permissions.
Two or more permissions in bitwise OR combinations can be
checked at one time.
- R_OK Test for read permission.
- W_OK Test for write permission.
- X_OK Test for execute permission.
- F_OK Test for existence of file.
The library "const/Filesys.lsp" must be required to use the constants listed above.
Example
Gamma> require_lisp("const/Filesys");
"/usr/cogent/lib/const/Filesys.lsp"
Gamma> system("touch /tmp/access_test");
0
Gamma> system("chmod a=rx /tmp/access_test");
0
Gamma> access("/tmp/access_test", R_OK|X_OK);
0
Gamma> access("/tmp/access_test", W_OK);
-1
Gamma>