title: O_TRUNC in system call "open()" not actually deleting contents of file
body: <p>From what I understand, the <code>O_TRUNC</code> specifier for the <code>open()</code> function should delete what's in the file first, then start writing.<br>
  Instead what it's doing is just having me overwrite what's in the file as I go.<br>
  My issue is the file contains the ASCII '11', and what it should do is read that and overwrite it to '8', but the file ends up as '81' as it's not deleting the whole thing before writing.<br>
  The goal of the code is to read the number in the file, decrement it by 3, then put that number back in the file, using only system calls.</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  
  int main(int argc, char*argv[]){
  
      int fp = open("file.txt", O_RDONLY);
      char c1, c2, c3='\n';
  
      read(fp, &amp;c1, 1);
      read(fp, &amp;c2, 1);
      close(fp);
      fp = open("file.txt", O_TRUNC || O_WRONLY);
  
      if (c2 == '\n')
          c1 -= 3;
      else {
          if (c2 &gt;= '0' &amp;&amp; c2 &lt;= '2' ) {
              c1--;
              c2 += 7;
          }
          else
              c2 -= 3;
  
      }
      if (c1 != '0')
          write(fp,&amp;c1,1);
      if (c2 != '\n')
          write(fp,&amp;c2,1);
      write(fp,&amp;c3,1);
      return 0;
  }
  </code></pre>