access
Determines accessibility of a file.
Defined in header <io.h>
Syntax
#include <io.h>
int access(const char *filename, intamode);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ |
Remarks
access checks the file named by filename to determine if it exists, and whether it can be read, written to, or executed.
The list of amode values is as follows:
06 Check for read and write permission 04 Check for read permission 02 Check for write permission 01 Execute (ignored) 00 Check for existence of file
Under DOS, all existing files have read access {amode equals 04), so 00 and 04 give the same result. In the same vein, amode values of 06 and 02 are equivalent because under DOS write access implies read access.
\i filename refers to a directory, access simply determines whether the directory exists.
Return value
If the requested access is allowed, access returns 0; otherwise, it returns a value of -1, and the global variable err no is set to one of the following:
ENOENT Path or file name not found EACCES Permission denied
See also
Example
#include <stdio.h>
#include <io.h>
int file_exists(char *filename) ;
int main(void) {
printfC'Does NOTEXIST.FIL exist: %s\n",
file_exists("NOTEXISTS.FIL") ? "YES" "NO")
return 0;
}
int file_exists(char *filename) {
return (access (filename, 0) == 0);
}
Program output
Does NOTEXIST.FIL exist? NO
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/io.h/access/
· short form /3.1/access/