access

Checks a file to see whether a specified access mode is allowed. This function only checks UIC protection; ACLs are not checked.


Note
The access function does not accept network files as arguments.

Format

#include  <unistd.h>

int access  (const char *file_spec, int mode);

Arguments

file_spec
A character string that gives an OpenVMS or UNIX style file specification. The usual defaults and logical name translations are applied to the file specification.
mode
Interpreted as shown in Table 3.

Table 3 Interpretation of the mode Argument

Mode Argument  Access Mode 
F_OK  Tests to see if the file exists 
X_OK  Execute 
W_OK  Write (implies delete access) 
R_OK  Read 

Combinations of access modes are indicated by ORing the values. For example, to check to see if a file has RWED access mode, invoke access as follows:

access (file_spec, R_OK | W_OK | X_OK);

Return Values
Indicates that the access is allowed. 
-1  Indicates that the access is not allowed. 

Example

    #include <unistd.h>
    
    main()
    {
    if (access("cdtm$:[c.don]dtm.com",0))
            perror("ACCESS - FAILED"),
             exit(2);
    
    }
    


Previous Page | Next Page | Table of Contents | Index