guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/5] [mingw]: Delete existing target file before attempting renam


From: Jan Nieuwenhuizen
Subject: [PATCH 4/5] [mingw]: Delete existing target file before attempting rename.
Date: Tue, 15 Feb 2011 16:35:02 +0100

From: Jan Nieuwenhuizen <address@hidden>

2011-02-15  Jan Nieuwenhuizen  <address@hidden>

        * libguile/filesys.c [MINGW32] (my_rename): Add implementation
        that deletes target if it exists.  Fixes rename behaviour.
---
 libguile/filesys.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/libguile/filesys.c b/libguile/filesys.c
index 880ee86..a2be2d5 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -680,9 +680,10 @@ SCM_DEFINE (scm_link, "link", 2, 0, 0,
 #undef FUNC_NAME
 #endif /* HAVE_LINK */
 
-#ifdef HAVE_RENAME
+#if defined (HAVE_RENAME) && !defined (__MINGW32__)
 #define my_rename rename
-#else
+#else /* !HAVE_RENAME || __MINGW32__ */
+#ifndef __MINGW32__
 static int
 my_rename (const char *oldname, const char *newname)
 {
@@ -698,7 +699,24 @@ my_rename (const char *oldname, const char *newname)
     }
   return rv;
 }
-#endif
+#else /* __MINGW32__ */
+static int
+my_rename (const char *oldname, const char *newname)
+{
+  int rv;
+  struct stat stat;
+
+  SCM_SYSCALL (rv = !stat (newname, &stat));
+  if (rv != 0)
+    SCM_SYSCALL (rv = unlink (newname));
+  if (rv == 0)
+    rv = rename (oldname, newname);
+
+  return rv;
+}
+#endif /* __MINGW32__ */
+#endif /* !HAVE_RENAME || __MINGW32__ */
+
 
 SCM_DEFINE (scm_rename, "rename-file", 2, 0, 0,
             (SCM oldname, SCM newname),
-- 
1.7.1

-- 
Jan Nieuwenhuizen <address@hidden> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar®  http://AvatarAcademy.nl  



reply via email to

[Prev in Thread] Current Thread [Next in Thread]