[project @ 2002-01-07 15:29:56 by sof]
authorsof <unknown>
Mon, 7 Jan 2002 15:29:57 +0000 (15:29 +0000)
committersof <unknown>
Mon, 7 Jan 2002 15:29:57 +0000 (15:29 +0000)
Ho-hum, readdir() and readdir_r() with GNU libc doesn't
flag the end of the directory stream the same way. Cope.

ghc/lib/std/Directory.lhs
ghc/lib/std/cbits/dirUtils.c

index 00234a3..84effa4 100644 (file)
@@ -346,10 +346,13 @@ getDirectoryContents path = do
       if (r == 0) 
         then do
                 dEnt    <- peek ptr_dEnt
-                entry   <- (d_name dEnt >>= peekCString)
-                freeDirEnt dEnt
-                entries <- loop ptr_dEnt dir
-                return (entry:entries)
+                if (dEnt == nullPtr) 
+                  then return []
+                  else do
+                   entry   <- (d_name dEnt >>= peekCString)
+                   freeDirEnt dEnt
+                   entries <- loop ptr_dEnt dir
+                   return (entry:entries)
         else do errno <- getErrno
                 if (errno == eINTR) then loop ptr_dEnt dir else do
                 throwErrnoIfMinus1_ "getDirectoryContents" $ closedir dir
index e47ff17..4277797 100644 (file)
@@ -79,7 +79,6 @@ prel_readdir(HsAddr dirPtr, HsAddr pDirEnt)
   struct dirent **pDirE = (struct dirent**)pDirEnt;
 #if HAVE_READDIR_R
   struct dirent* p;
-  struct dirent* r;
   int res;
   static unsigned int nm_max = -1;
   
@@ -96,6 +95,7 @@ prel_readdir(HsAddr dirPtr, HsAddr pDirEnt)
 #endif
   }
   p = (struct dirent*)malloc(sizeof(struct dirent) + nm_max);
+  if (p == NULL) return -1;
   res = readdir_r((DIR*)dirPtr, p, pDirE);
   if (res != 0) {
     *pDirE = NULL;