on ef3aed2 help sign in
Idris-dev/src/Util/System.hs
29 lines 749 B history raw
1{-# LANGUAGE CPP #-}
2module Util.System(tempfile,environment) where
4-- System helper functions.
6import System.Environment
7import System.IO
8#if MIN_VERSION_base(4,0,0)
9import Control.Exception as CE
10#endif
12#if MIN_VERSION_base(4,0,0)
13catchIO :: IO a -> (IOError -> IO a) -> IO a
14catchIO = CE.catch
15#else
16catchIO = catch
17#endif
19tempfile :: IO (FilePath, Handle)
20tempfile = do env <- environment "TMPDIR"
21 let dir = case env of
22 Nothing -> "/tmp"
23 (Just d) -> d
24 openTempFile dir "idris"
26environment :: String -> IO (Maybe String)
27environment x = catchIO (do e <- getEnv x
28 return (Just e))
29 (\_ -> return Nothing)