MicroHs-0.9.17.0: ghc/System/IO/Extra.hs
module System.IO.Extra(openFileM, openTmpFile) where
import System.Environment
import System.IO
openFileM :: FilePath -> IOMode -> IO (Maybe Handle)
openFileM path m = do
r <- (try $ openFile path m) :: IO (Either IOError Handle)
case r of
Left _ -> return Nothing
Right h -> return (Just h)
openTmpFile :: String -> IO (String, Handle)
openTmpFile tmplt = do
mtmp <- lookupEnv "TMPDIR"
let tmp = fromMaybe "/tmp" mtmp
res <- try $ openTempFile tmp tmplt
case res of
Right x -> return x
Left (_::SomeException) -> openTempFile "." tmplt