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?

Below is a bare bones example which illustrates the problem. The first run works, but the second produces the "permission denied" error.

Thanks for the tip. I added S_IRUSR | S_IWUSR, but no dice.
–
ZachApr 1 '11 at 16:27

humm... sorry about that. i'm sure there's a way without win32 calls, but I can't remember right now.
–
MatApr 1 '11 at 16:30

not a problem. As a kludge I can system("rm filename"). But it would be nice to know a more appropriate way to handle this. My code works fine in unix, but trying to get things going on windows is a bit of a learning curve.
–
ZachApr 1 '11 at 16:32

slightly less kludgy is to use the unlink function. still not pretty, and as with anything of that order it's racy (file could be re-created between the unlink and open call).
–
MatApr 1 '11 at 16:44

I'll try that out. Raciness shouldn't be a problem in the current use case.
–
ZachApr 1 '11 at 16:52