+
+/* rename() on Windows fails if the destination file exists. Fix it. */
+int
+rename_replacement(const char *oldpath, const char *newpath)
+{
+ if (MoveFileExA(oldpath, newpath, MOVEFILE_REPLACE_EXISTING)) {
+ return 0;
+ } else {
+ /* As usual, the possible error values are not documented */
+ DWORD err = GetLastError();
+ ERROR("MoveFileExA(): Can't rename \"%s\" to \"%s\"",
+ oldpath, newpath);
+ win32_error(err);
+ errno = 0;
+ return -1;
+ }
+}