[MLton-commit] r5480

Matthew Fluet fluet at mlton.org
Thu Mar 29 06:59:46 PST 2007


Patch from Nicolas Bertolotti (PolySpace).

- bug-fix-rename-mingw.patch

This patch fixes the rename() function whose behavior is not the same on
MinGW than Unix (with MinGW, rename fails when the destination file exists
whereas the Unix specification is to replace the existing file).


----------------------------------------------------------------------

U   mlton/trunk/runtime/basis/Posix/FileSys/rename.c

----------------------------------------------------------------------

Modified: mlton/trunk/runtime/basis/Posix/FileSys/rename.c
===================================================================
--- mlton/trunk/runtime/basis/Posix/FileSys/rename.c	2007-03-29 14:48:17 UTC (rev 5479)
+++ mlton/trunk/runtime/basis/Posix/FileSys/rename.c	2007-03-29 14:59:46 UTC (rev 5480)
@@ -1,5 +1,17 @@
 #include "platform.h"
 
 C_Errno_t(C_Int_t) Posix_FileSys_rename (NullString8_t p1, NullString8_t p2) {
-  return rename ((const char*) p1, (const char*) p2);
+  C_Errno_t(C_Int_t) res;
+  res = rename ((const char *) p1, (const char *) p2);
+#ifdef __MINGW32__
+  /* the MinGW rename() function does not remove the destination file 
+   * if it exists; we emulate the Unix behavior here. 
+   */
+  if ((res != 0) && (errno == EEXIST)) {
+    res = unlink ((const char *) p2);
+    if (res == 0)
+      res = rename((const char *) p1, (const char *) p2);
+  }
+#endif
+  return res;
 }




More information about the MLton-commit mailing list