title: Unix: write() when offset is larger than size
body: <p>I have the following code:  </p>
  
  <pre><code> #include &lt;ctype.h&gt;
      #include &lt;fcntl.h&gt;
      #include &lt;unistd.h&gt;
      #include &lt;sys/types.h&gt;
      #include &lt;sys/stat.h&gt;
  
      char buf[]="wimpykid";
      char buff[100];
      void pri(int fd);
      int main(){
         int i=0,fd;
         fd=creat("ifile", S_IRUSR|S_IWUSR); pri(fd);
         write(fd, buf, 8); pri(fd);
  
         lseek(fd, 23, SEEK_CUR);  pri(fd);
         while(buf[i]!='\0'){
          if(i%2)
             buf[i]=toupper(buf[i]);i++;
         }
         write(fd, buf,8);  pri(fd);
      exit(0);
  }
  //print the current offset
  void pri(int fd){
      printf("%d\n", lseek( fd, 0, SEEK_CUR));
  }
  </code></pre>
  
  <p>And the output is 0,8,31,39. After the first write, the offset is now 8. The file has only 8 chars in it, but how could I add 23 to the current offset? If I've done so, when I write another 8 chars to it, where will the 8 chars start at? The output shows the second 8 chars just follow the first 8 directly. I don't quite understand.</p>