int access(const char *filenpath, int mode);
功 能: 确定文件或文件夹的访问权限。
file/access.c
1 #include "apue.h" 2 #include <fcntl.h> 3 int 4 main(int argc, char *argv[]) 5 { 6 if (argc != 2) 7 err_quit("usage: a.out <pathname>"); 8 if (access(argv[1], R_OK) < 0) 9 err_ret("access error for %s", argv[1]); 10 else 11 printf("read access OK\n"); 12 if (open(argv[1], O_RDONLY) < 0) 13 err_ret("open error for %s", argv[1]); 14 else 15 printf("open for reading OK\n"); 16 exit(0); 17 }
原文地址:http://www.cnblogs.com/paullam/p/3850339.html