diff --git a/cbits/HsUnix.c b/cbits/HsUnix.c index 616f546..be46545 100644 --- a/cbits/HsUnix.c +++ b/cbits/HsUnix.c @@ -106,7 +106,7 @@ char *__hscore_d_name( struct dirent* d ) char __hscore_d_type( struct dirent* d ) { -#ifdef HAVE_DIRENT_D_TYPE +#ifdef HAVE_STRUCT_DIRENT_D_TYPE return (d->d_type); #else return CONST_DT_UNKNOWN; diff --git a/tests/DirEntType.hs b/tests/DirEntType.hs new file mode 100644 index 0000000..889bc6f --- /dev/null +++ b/tests/DirEntType.hs @@ -0,0 +1,33 @@ +{-# LANGUAGE LambdaCase #-} + +module Main (main) where + +import Control.Exception (bracket) +import Foreign.C.String (peekCString) +import System.Exit (die) +import System.Posix.Directory +import System.Posix.Directory.Internals +import Text.Printf (printf) + +peekDirEnt :: DirEnt -> IO (String, DirType) +peekDirEnt dirEnt = do + dName <- dirEntName dirEnt >>= peekCString + dType <- dirEntType dirEnt + return (dName, dType) + +testDirTypeOfProcSelf :: DirStream -> IO () +testDirTypeOfProcSelf dirStream = go where + go = readDirStreamWith peekDirEnt dirStream >>= \case + Just (dName, dType) -> case dName of + "self" -> case dType of + SymbolicLinkType -> return () + _ -> die $ + printf "DirEnt of /proc/self has %s; expected %s!" + (show dType) + (show SymbolicLinkType) + _ -> go + Nothing -> die + "Didn't find \"self\" DirEnt while reading /proc DirStream!" + +main :: IO () +main = bracket (openDirStream "/proc") closeDirStream testDirTypeOfProcSelf diff --git a/unix.cabal b/unix.cabal index 7df7270..e8ef1c2 100644 --- a/unix.cabal +++ b/unix.cabal @@ -382,3 +382,15 @@ test-suite T13660 else build-depends: filepath >= 1.4.100.0 && < 1.5.0.0 ghc-options: -Wall + +test-suite DirEntType + if !os(linux) + build-depends: unbuildable<0 + buildable: False + + hs-source-dirs: tests + main-is: DirEntType.hs + type: exitcode-stdio-1.0 + default-language: Haskell2010 + build-depends: base, unix + ghc-options: -Wall