程序4-2 access函数实例

 1 //http://blog.chinaunix.net/uid-24549279-id-71355.html
 2 /*
 3  ============================================================================
 4  Name        : test.c
 5  Author      : blank
 6  Version     :
 7  Copyright   : Your copyright notice
 8  Description : 程序4-2 access函数实例
 9  ============================================================================
10 */
11 
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <sys/stat.h>
15 #include "ourhdr.h"
16 
17 #define BUFFSIZE 4096
18 
19 int main(int argc, char *argv[])
20 {
21     if (argc != 2){
22         err_quit("usage: ./test <filename>\n");
23     }
24 
25     if (access(argv[1], R_OK) < 0){
26         err_ret("access error for %s", argv[1]);
27     }else{
28         printf("read access OK\n");
29     }
30 
31     if (open(argv[1], O_RDONLY) < 0){
32         err_ret("open error for %s", argv[1]);
33     }else{
34         printf("open for read OK\n");
35     }
36 
37     exit(0);
38 }

 

posted @ 2014-04-27 11:50  blankqdb  阅读(479)  评论(0编辑  收藏  举报