access() Check File Permission Setting
#include <io.h>
int access(pathname,mode);
char *pathname; Name of file or directory
int mode; Permission setting
access() checks whether the file or directory specified as `pathname'
exists, and whether its read/write mode matches that that of the
argument `mode'. 'mode' can have any of the following values:
Value Checks For
00 Existence only
02 Write permission
04 Read permission
06 Read and write permission
Returns: Zero if the file has the given mode, or -1 if the file
does not exist or does not have the given mode. If an
error occurs, 'errno' is set to one of the following:
EACCES Access denied; file's permission does
not allow the specified access
ENOENT File or pathname not found.
Notes: In MS-DOS all existing files have read access, so this
function determines whether or not a file can be written
to. In MS-DOS all directories have read and write access,
so this function determines whether or not a directory
exists.
-------------------------------- Example ---------------------------------
The following statements check for write permission and print an
error message.
#include <io.h>
#include <stdlib.h> /* For perror */
main()
{
if ((access("inventory.dta",2)) == -1)
perror("cannot write to inventory file");
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster