Commit 49625c6c authored by rrt's avatar rrt
Browse files

[project @ 2001-02-14 12:36:06 by rrt]

Make isDirectory work on Windows (dirent.d_name is a char *, not a char []);
also getDirectoryContents (readdir helpfully sets errno to ENOENT when we've
read the last entry, rather than leaving it at 0).

Windows is *not* the way of the future.
parent 8b638c86
-- -----------------------------------------------------------------------------
-- $Id: Directory.hsc,v 1.5 2001/02/13 15:23:33 rrt Exp $
-- $Id: Directory.hsc,v 1.6 2001/02/14 12:36:06 rrt Exp $
--
-- (c) The University of Glasgow, 1994-2000
--
......@@ -340,7 +340,7 @@ The path refers to an existing non-directory object.
getDirectoryContents :: FilePath -> IO [FilePath]
getDirectoryContents path = do
p <- withUnsafeCString path $ \s ->
throwErrnoIfNullRetry "getDirectoryContents" (opendir s)
throwErrnoIfNullRetry "getDirectoryContents1" (opendir s)
loop p
where
loop :: Ptr CDir -> IO [String]
......@@ -348,15 +348,25 @@ getDirectoryContents path = do
resetErrno
p <- readdir dir
if (p /= nullPtr)
then do entry <- peekCString ((#ptr struct dirent,d_name) p)
then do
#ifndef mingw32_TARGET_OS
entry <- peekCString ((#ptr struct dirent,d_name) p)
#else
entryp <- (#peek struct dirent,d_name) p
entry <- peekCString entryp -- on mingwin it's a char *, not a char []
#endif
entries <- loop dir
return (entry:entries)
else do errno <- getErrno
if (errno == eINTR) then loop dir else do
throwErrnoIfMinus1_ "getDirectoryContents" $ closedir dir
throwErrnoIfMinus1_ "getDirectoryContents2" $ closedir dir
#ifndef mingw32_TARGET_OS
if (errno == eOK)
#else
if (errno == eNOENT) -- mingwin (20001111) cunningly sets errno to ENOENT when it runs out of files
#endif
then return []
else throwErrno "getDirectoryContents"
else throwErrno "getDirectoryContents3"
{-
If the operating system has a notion of current directories,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment