title: Using MinGW how can I create a file without the read-only file attribute?
body: <p>When I attempt to overwrite an existing file, I get a "permission denied" error.
  I noticed that the file which is created has the "Read-only" attribute set. When I manually unset this I can then overwrite the file. Is there some flag I can pass to open() which will automatically unset this when I create a file?</p>
  
  <p>Below is a bare bones example which illustrates the problem. The first run works, but the second produces the "permission denied" error.</p>
  
  <p>Thanks,
  Zach (New to MingW/Windows 7)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;errno.h&gt;
  
  int main(int argc, char ** argv) {
      int fid;
      double data = 12.0;
  
      if ( (fid = open("junk.data", O_WRONLY | O_CREAT | O_BINARY)) == -1 ) {
          printf("ERROR opening.\n\terror is:%s\n", strerror(errno));
          return 1;
      }
  
      write(fid, &amp;data, sizeof(double));
  
      close(fid);
  
      return 0;
  }
  </code></pre>