on bd89fdc help sign in
Idris-dev/src/Util/System.hs
35 lines 916 B history raw
1{-# LANGUAGE CPP #-}
2module Util.System(tempfile,environment,getCC) 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
19getCC :: IO String
20getCC = do env <- environment "IDRIS_CC"
21 case env of
22 Nothing -> return "gcc"
23 Just cc -> return cc
25tempfile :: IO (FilePath, Handle)
26tempfile = do env <- environment "TMPDIR"
27 let dir = case env of
28 Nothing -> "/tmp"
29 (Just d) -> d
30 openTempFile dir "idris"
32environment :: String -> IO (Maybe String)
33environment x = catchIO (do e <- getEnv x
34 return (Just e))
35 (\_ -> return Nothing)