#include<unistd.h>
#include<stdio.h>
int main( void )
{
char sFileName[128];
int iRet = 0;
memset(sFileName, 0, sizeof(sFileName));
sprintf(sFileName, "test.txt");
printf("R_OK[%d], W_OK[%d], X_OK[%d], F_OK[%d]\n", R_OK, W_OK, X_OK, F_OK);
iRet = access(sFileName, R_OK);
if( iRet < 0 )
{
printf("%s %d err, iRet[%d]!\n", sFileName, R_OK, iRet);
return -1;
}
return 0;
#include<stdio.h>
int main( void )
{
char sFileName[128];
int iRet = 0;
memset(sFileName, 0, sizeof(sFileName));
sprintf(sFileName, "test.txt");
printf("R_OK[%d], W_OK[%d], X_OK[%d], F_OK[%d]\n", R_OK, W_OK, X_OK, F_OK);
iRet = access(sFileName, R_OK);
if( iRet < 0 )
{
printf("%s %d err, iRet[%d]!\n", sFileName, R_OK, iRet);
return -1;
}
return 0;
}
运行结果:
R_OK[4], W_OK[2], X_OK[1], F_OK[0]
test.txt 4 err, iRet[-1]!
新建test.txt后,运行结果:
R_OK[4], W_OK[2], X_OK[1], F_OK[0]