openBinaryTempFile,
) where
-import Control.Exception hiding (bracket)
+import Control.Exception
#ifndef __NHC__
import Data.Bits
#endif
#ifdef __GLASGOW_HASKELL__
-import GHC.IOBase as ExceptionBase
-#endif
-#ifdef __HUGS__
-import Hugs.Exception as ExceptionBase
-#endif
-
-#ifdef __GLASGOW_HASKELL__
import GHC.Base
import GHC.IOBase -- Together these four Prelude modules define
import GHC.Handle -- all the stuff exported by IO for the GHC version
import Hugs.IO
import Hugs.IOExts
import Hugs.IORef
-import Hugs.Prelude ( throw, Exception(NonTermination) )
-import Control.Exception ( bracket )
import System.IO.Unsafe ( unsafeInterleaveIO )
#endif
-- XXX We want to tell fdToHandle what the filepath is,
-- as any exceptions etc will only be able to report the
-- fd currently
- h <- fdToHandle fd
- `ExceptionBase.catchAny` \e -> do c_close fd; throw e
+ h <- fdToHandle fd `onException` c_close fd
return (filepath, h)
#endif
where
-- It follows that an attempt to write to a file (using 'writeFile', for
-- example) that was earlier opened by 'readFile' will usually result in
-- failure with 'System.IO.Error.isAlreadyInUseError'.
-
--- -----------------------------------------------------------------------------
--- Utils
-
-#ifdef __GLASGOW_HASKELL__
--- Copied here to avoid recursive dependency with Control.Exception
-bracket
- :: IO a -- ^ computation to run first (\"acquire resource\")
- -> (a -> IO b) -- ^ computation to run last (\"release resource\")
- -> (a -> IO c) -- ^ computation to run in-between
- -> IO c -- returns the value from the in-between computation
-bracket before after thing =
- block (do
- a <- before
- r <- catchAny
- (unblock (thing a))
- (\e -> do { after a; throw e })
- after a
- return r
- )
-#endif