[project @ 2005-01-31 12:57:26 by simonmar]
[ghc-base.git] / cbits / dirUtils.c
index b3fb6c0..fdcdf29 100644 (file)
@@ -4,17 +4,17 @@
  * Directory Runtime Support
  */
 
-#include "config.h"
+#include "ghcconfig.h"
 
 // The following is required on Solaris to force the POSIX versions of
 // the various _r functions instead of the Solaris versions.
-#ifdef solaris2_TARGET_OS
+#ifdef solaris2_HOST_OS
 #define _POSIX_PTHREAD_SEMANTICS
 #endif
 
 #include "HsBase.h"
 
-#if defined(mingw32_TARGET_OS)
+#if defined(mingw32_HOST_OS) || defined(__MINGW32__) || defined(_MSC_VER)
 #include <windows.h>
 
 static
@@ -63,7 +63,7 @@ __hscore_readdir( HsAddr dirPtr, HsAddr pDirEnt )
 #if HAVE_READDIR_R
   struct dirent* p;
   int res;
-  static unsigned int nm_max = -1;
+  static unsigned int nm_max = (unsigned int)-1;
   
   if (pDirE == NULL) {
     return -1;
@@ -81,7 +81,11 @@ __hscore_readdir( HsAddr dirPtr, HsAddr pDirEnt )
   if (p == NULL) return -1;
   res = readdir_r((DIR*)dirPtr, p, pDirE);
   if (res != 0) {
-    *pDirE = NULL;
+      *pDirE = NULL;
+      free(p);
+  }
+  else if (*pDirE == NULL) {
+    // end of stream
     free(p);
   }
   return res;
@@ -113,7 +117,7 @@ HsInt
 __hscore_renameFile( HsAddr src,
                     HsAddr dest)
 {
-#if (defined(_MSC_VER) || defined(_WIN32))
+#if defined(mingw32_HOST_OS) || defined(__MINGW32__) || defined(_MSC_VER)
     static int forNT = -1;
     
     /* ToDo: propagate error codes back */