title: Default write behaviour - O_TRUNC or O_APPEND?
body: <p>What is the default behaviour when you <code>open</code> a file with access mode <code>O_WRONLY</code> or <code>O_RDWR</code>. Is the file opened in append mode or truncate mode? From the <a href="http://man7.org/linux/man-pages/man2/open.2.html" rel="noreferrer">man pages</a>:</p>
  
  <blockquote>
    <p>The argument flags must include one of the following access modes:
    O_RDONLY, O_WRONLY, or O_RDWR.<br>
    ...<br>
    In addition, <strong>zero</strong> or more <em>file creation</em> flags and <em>file status</em> flags can be bitwise-or'd in flags.</p>
  </blockquote>
  
  <p>This sounds like <code>O_APPEND</code> and <code>O_TRUNC</code> flags are optional. So what does the following do?</p>
  
  <pre><code>void main ( void )
  {
      int fd = open( "foo.txt", O_WRONLY );
  
      write( fd, "hello", 5 );
  
      close( fd );
  }
  </code></pre>