分类: C/C++
2010-07-10 17:28:50
Determine file-access permission.
int _access( const char *path, int mode );
mode Value
Checks File For
00
Existence only
02
Write permission
04
Read permission
06
Read and write permission
头文件 #include
Example
/* ACCESS.C: This example uses _access to check the
* file named "ACCESS.C" to see if it exists and if
* writing is allowed.
*/
#include
#include
#include
void main( void )
{
/* Check for existence */
if( (_access( "ACCESS.C", 0 )) != -1 )
{
printf( "File ACCESS.C exists\n" );
/* Check for write permission */
if( (_access( "ACCESS.C", 2 )) != -1 )
printf( "File ACCESS.C has write permission\n" );
}
}
Output
File ACCESS.C exists
File ACCESS.C has write permission