Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. /*lsp dup()예제 90p~91p*/
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <fcntl.h>
  6.  
  7. #define BUFFER_SIZE 1024
  8.  
  9. int main()
  10. {
  11. char buf[BUFFER_SIZE];
  12. char * fname = "ssu_test.txt";
  13. int count;
  14. int fd1, fd2;
  15.  
  16. if((fd1 = open(fname, O_RDONLY, 0644)) < 0){
  17. fprintf(stderr, "open error for %s\n", fname);
  18. exit(1);
  19. }
  20.  
  21. fd2 = dup(fd1);
  22. count = read(fd1, buf, 12);
  23. buf[count] = 0;
  24. printf("fd1's printf : %s\n", buf);
  25. lseek(fd1, 1, SEEK_CUR);
  26. count = read(fd2, buf, 12);
  27. buf[count] = 0;
  28. printf("fd2's printf : %s\n", buf);
  29. exit(0);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement