Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 24th, 2012  |  syntax: None  |  size: 0.67 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "apue.h"
  2. #include <fcntl.h>
  3. #include <string.h>
  4.  
  5. char    buf1[] = "abcdefghij";
  6. char    buf2[] = "ABCDEFGHIJ";
  7.  
  8. int main()
  9. {
  10.         int fd = open("file.hole", O_WRONLY | O_CREAT | O_TRUNC, FILE_MODE);
  11.         if (fd == -1)
  12.         {
  13.                 err_sys("create file.hole error");
  14.         }
  15.  
  16.         if (write(fd, buf1, strlen(buf1)) != strlen(buf1))
  17.         {
  18.                 err_sys("write buf1 error");
  19.         }
  20.  
  21.         if (lseek(fd, 16384, SEEK_SET) == -1)
  22.         {
  23.                 err_sys("lseek error");
  24.         }
  25.  
  26.         if (write(fd, buf2, strlen(buf2)) != strlen(buf2))
  27.         {
  28.                 err_sys("write buf2 error");
  29.         }
  30.  
  31.         return 0;
  32. }