#include <io.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
/* Check for existence */
if( (_access( "crt_ACCESS.TXT", 0 )) != -1 )
{
printf( "File crt_ACCESS.TXT exists\n" );
/* Check for write permission */
/* assume file is read-only */
if( (_access( "crt_ACCESS.TXT", 2 )) == -1 )
printf( "File crt_ACCESS.C does not have write permission\n" );
}
}
/*
Parameters
path
File or directory path.
mode
Permission setting.
Return Value
Each function returns 0 if the file has the given mode. The function returns –1 if the named file does not exist or is not accessible in the given mode; in this case, errno is set as follows:
EACCES
Access denied: file's permission setting does not allow specified access.
ENOENT
Filename or path not found.
mode value Checks file for
00 Existence only
02 Write permission
04 Read permission
06 Read and write permission
0 comments:
Post a Comment