Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. /*lsp lseek예제2 73p~74p*/
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <fcntl.h>
  6. #include <sys/stat.h>
  7.  
  8. #define CREAT_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
  9.  
  10. char buf1[] = "1234567890";
  11. char buf2[] = "ABCDEFGHIJ";
  12.  
  13. int main()
  14. {
  15.     char * fname = "ssu_hole.txt";
  16.     int fd;
  17.  
  18.     if((fd = creat(fname, CREAT_MODE)) < 0){
  19.         fprintf(stderr, "creat error for %s\n", fname);
  20.         exit(1);
  21.     }
  22.  
  23.     if(write(fd, buf1, 12) != 12){
  24.         fprintf(stderr, "buf1 write error\n");
  25.         exit(1);
  26.     }
  27.  
  28.     if(lseek(fd, 15000, SEEK_SET) < 0){
  29.         fprintf(stderr, "lseek error\n");
  30.         exit(1);
  31.     }
  32.  
  33.     if(write(fd, buf2, 12) != 12){
  34.         fprintf(stderr, "buf2 write error\n");
  35.         exit(1);
  36.     }
  37.  
  38.     exit(0);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement