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 }

 

相关文章:

  • 2021-12-18
  • 2021-11-04
  • 2022-12-23
  • 2021-05-18
  • 2021-08-11
  • 2021-12-27
  • 2021-08-14
  • 2021-10-21
猜你喜欢
  • 2021-12-26
  • 2021-12-18
  • 2021-10-17
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案