#include
int access (const char *pathname, int mode)
mode 说明
R_OK 测试读许可权
W_OK 测试写许可权
X_OK 测试执行许可权
F_OK 测试文件是否存在
1 #include
2 #include
3 #include
4 #include
5
6
7 main(int argc, char *argv[])
8 {
9 if(argc != 2)
10 printf("usage: a.out \n");
11 if(access(argv[1], R_OK) < 0)
12 printf("access error for %s\n", argv[1]);
13 else
14 printf("read access OK\n");
15 if(open(argv[1], O_RDONLY) < 0)
16 printf("open error for %s\n",argv[1]);
17 else
18 printf("open for reading OK\n");
19 exit(0);
20 }