HAR1F

Untitled

May 24th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int main()
  7. {
  8.    int     fd;
  9.    size_t  size;
  10.    char    string[] = "Hello, world!";
  11.  
  12.    (void)umask(0);
  13.  
  14.    if((fd = open("myfile", O_WRONLY | O_CREAT, 0666)) < 0){
  15.      printf("Can\'t open file\n");
  16.      exit(-1);
  17.    }
  18.  
  19.    size = write(fd, string, 14);
  20.  
  21.    if(size != 14){
  22.      printf("Can\'t write all string\n");
  23.      exit(-1);
  24.    }
  25.  
  26.    if(close(fd) < 0){
  27.      printf("Can\'t close file\n");
  28.    }
  29.  
  30.    return 0;
  31. }
Add Comment
Please, Sign In to add comment