APUE Learning Example Source Code
Guo Wenxue
2018-12-07 6632fe9c973b5281a359e533a7820961176057fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
 
int main(int argc, char **argv)
{
  char   *file_name = "/test.txt";
  int    fd=-1;
  
  fd=open(file_name, O_RDONLY, 066);
  if( fd < 0 )
  {
      perror("Open file failure");  
      printf("Open file %s failure: %s\n", file_name, strerror(errno));  
      return 0;
  }
 
  close(fd);
}