Advertisement
teknoraver

(f)open

Aug 18th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include <stdio.h>
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     char buf[256];
  10.     int fd;
  11.     FILE *file;
  12.  
  13.     puts("open()");
  14.     fd = open(argv[1], O_RDONLY);
  15.     if(fd < 0) {
  16.         perror("open");
  17.         return 1;
  18.     }
  19.     while(read(fd, buf, 1) > 0)
  20.         putchar(buf[0]);
  21.     close(fd);
  22.  
  23.     puts("\nfopen()");
  24.     file = fopen(argv[1], "r");
  25.     while(fread(buf, 1, 1, file))
  26.         putchar(buf[0]);
  27.     fclose(file);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement