@@ -0,0 +1,29 @@
1+{-# LANGUAGE CPP #-}
2+module Util.System(tempfile,environment) where
3+
4+-- System helper functions.
5+
6+import System.Environment
7+import System.IO
8+#if MIN_VERSION_base(4,0,0)
9+import Control.Exception as CE
10+#endif
11+
12+#if MIN_VERSION_base(4,0,0)
13+catchIO :: IO a -> (IOError -> IO a) -> IO a
14+catchIO = CE.catch
15+#else
16+catchIO = catch
17+#endif
18+
19+tempfile :: IO (FilePath, Handle)
20+tempfile = do env <- environment "TMPDIR"
21+ let dir = case env of
22+ Nothing -> "/tmp"
23+ (Just d) -> d
24+ openTempFile dir "esc"
25+
26+environment :: String -> IO (Maybe String)
27+environment x = catchIO (do e <- getEnv x
28+ return (Just e))
29+ (\_ -> return Nothing)