From: sof Date: Mon, 7 Jan 2002 15:29:57 +0000 (+0000) Subject: [project @ 2002-01-07 15:29:56 by sof] X-Git-Tag: Approximately_9120_patches~313 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=57401ae52020db4ab1d1d5b5e66d90fe3ad22a38;p=ghc-hetmet.git [project @ 2002-01-07 15:29:56 by sof] Ho-hum, readdir() and readdir_r() with GNU libc doesn't flag the end of the directory stream the same way. Cope. --- diff --git a/ghc/lib/std/Directory.lhs b/ghc/lib/std/Directory.lhs index 00234a3..84effa4 100644 --- a/ghc/lib/std/Directory.lhs +++ b/ghc/lib/std/Directory.lhs @@ -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 diff --git a/ghc/lib/std/cbits/dirUtils.c b/ghc/lib/std/cbits/dirUtils.c index e47ff17..4277797 100644 --- a/ghc/lib/std/cbits/dirUtils.c +++ b/ghc/lib/std/cbits/dirUtils.c @@ -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;