#include "HsBase.h"
-#if defined(mingw32_TARGET_OS)
+#if defined(mingw32_TARGET_OS) || defined(__MINGW32__) || defined(_MSC_VER)
#include <windows.h>
static
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;