title: Re-open file read-only in Linux (or POSIX)
body: <p>I open a file in read/write mode and do a series of reads, writes and seeks (from user input).</p>
  
  <p>At some point later on I want to make the file read-only to prevent any further writes to it.</p>
  
  <p>Is there a Linux (or POSIX) function to do that? Perhaps some <code>fcntl</code> call?</p>
  
  <p>Or is my only option is to save the current position in the file, close it and reopen <code>RD_ONLY</code>?</p>
  
  <pre><code>#include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;unistd.h&gt;
  
  int fd = open("/path/to/file", O_RDWR);
  
  // mixture of:
  write(fd, ...);
  lseek(fd, ...);
  read (fd, ...);
  // etc
  
  ...
  
  // make file read-only ???
  
  read (fd, ...); // OK
  lseek(fd, ...); // OK
  write(fd, ...); // error
  </code></pre>