[project @ 2003-11-21 16:24:44 by sof]
[haskell-directory.git] / cbits / dirUtils.c
index b3fb6c0..f256463 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "HsBase.h"
 
-#if defined(mingw32_TARGET_OS)
+#if defined(mingw32_TARGET_OS) || defined(__MINGW32__) || defined(_MSC_VER)
 #include <windows.h>
 
 static
@@ -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;