work around Win32 rename() issue using native API

As DGandalf suggested, here's a pull request for a nicer way to handle Windows rename()'s failure (or refusal) to overwrite existing files. I have not tested this on Cygwin, but from my understanding it should compile fine.