on master help sign in
Add missing file
commit2533b8d32f0e37e56ec8068145db537d8bf31950 authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateThu 20 Sep 2012, 17:28 (14 years ago) parent34e8788
1 file changed+29
src/Util/System.hs+29
src/Util/System.hsnew file+29
@@ -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)