APUE Learning Example Source Code
guowenxue
2023-11-06 d81310d55b9b7d07904c19f879f50e52fd7be489
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);
}