title: Why is data written to a file opened with O_APPEND flag, always written at the end, even with `lseek`?
body: <p>I have been given a programming assignment:</p>
  <blockquote>
  <p>Write a program that opens an existing file for writing with the O_APPEND flag, and then seeks to the beginning of the file before writing some data. Where does the data appear in the file? Why?</p>
  </blockquote>
  <p>What I have come up with is:</p>
  <pre><code>main() {
      int fd = open(&quot;test.txt&quot;, O_WRONLY | O_APPEND);
      lseek(fd, 0, SEEK_SET);
      write(fd, &quot;abc&quot;, 3);
      close(fd);
  }
  </code></pre>
  <p>Upon trying the above, I have found that the data is always written at the end of the file. Why is that? Is it because I have indicated <code>O_APPEND</code>?</p>