title: What is the best way to truncate the beginning of a file in C?
body: <p>There are many similar questions, but nothing that answers this specifically after googling around quite a bit.  Here goes:</p>
  
  <p>Say we have a file (could be binary, and much bigger too):</p>
  
  <blockquote>
    <p>abcdefghijklmnopqrztuvwxyz</p>
  </blockquote>
  
  <p>what is the best way in C to "move" a right most portion of this file to the left, truncating the beginning of the file.. so, for example, "front truncating" 7 bytes would change the file on disk to be:</p>
  
  <blockquote>
    <p>hijklmnopqrztuvwxyz</p>
  </blockquote>
  
  <p>I must avoid temporary files, and would prefer not to use a large buffer to read the whole file into memory.  One possible method I thought of is to use fopen with "rb+" flag, and constantly fseek back and forth reading and writing to copy bytes starting from offset to the beginning, then setEndOfFile to truncate at the end.  That seems to be a lot of seeking (possibly inefficient).</p>
  
  <p>Another way would be to fopen the same file twice, and use fgetc and fputc with the respective file pointers.  Is this even possible?</p>
  
  <p>If there are other ways, I'd love to read all of them.</p>