makedep: Handle non-overwriting rename for windows.

Dylan Smith dylan.ah.smith at gmail.com
Sat Aug 22 00:57:47 CDT 2009


When building on windows, makedep always fails because it depends on rename
to overwrite another file with the new filename.  This can be detected with
the EEXIST error code, so it will try to recover by removing the other file
before renaming again.

I chose not to always remove the file first, because that would give more
chance of an inconsistent state if remove works but rename fails.
---
 tools/makedep.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
-------------- next part --------------
diff --git a/tools/makedep.c b/tools/makedep.c
index e2ca5ad..654f5a7 100644
--- a/tools/makedep.c
+++ b/tools/makedep.c
@@ -960,7 +960,15 @@ static void output_dependencies(void)
 
     if (tmp_name)
     {
-        if (rename( tmp_name, OutputFileName ) == -1)
+        int ret;
+        ret = rename( tmp_name, OutputFileName );
+        if (ret == -1 && errno == EEXIST)
+        {
+            /* rename doesn't overwrite on windows */
+            remove( OutputFileName );
+            ret = rename( tmp_name, OutputFileName );
+        }
+        if (ret == -1)
         {
             unlink( tmp_name );
             fatal_error( "failed to rename output file to '%s'\n", OutputFileName );


More information about the wine-patches mailing list