From 880cb6cdf9f2492021abb5c756ef78f31457e82b Mon Sep 17 00:00:00 2001
From: Ian Lynagh <igloo@earth.li>
Date: Sun, 22 Jul 2007 15:27:52 +0000
Subject: [PATCH] open(Binary)TempFile is now portable

---
 System/IO.hs | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/System/IO.hs b/System/IO.hs
index 2970cf0b..c8b0f925 100644
--- a/System/IO.hs
+++ b/System/IO.hs
@@ -157,10 +157,8 @@ module System.IO (
 
     -- * Temporary files (not portable: GHC only)
 
-#ifdef __GLASGOW_HASKELL__
     openTempFile,
     openBinaryTempFile,
-#endif
   ) where
 
 import Data.Bits
@@ -170,6 +168,13 @@ import Foreign.C.Error
 import Foreign.C.String
 import System.Posix.Internals
 
+#ifdef __GLASGOW_HASKELL__
+import GHC.Exception    as ExceptionBase hiding (catch)
+#endif
+#ifdef __HUGS__
+import Hugs.Exception   as ExceptionBase
+#endif
+
 #ifdef __GLASGOW_HASKELL__
 import GHC.Base
 import GHC.IOBase	-- Together these four Prelude modules define
@@ -450,8 +455,11 @@ openTempFile' loc tmp_dir template binary = do
            then findTempName (x+1)
            else ioError (errnoToIOError loc errno Nothing (Just tmp_dir))
        else do
-         h <- fdToHandle' fd Nothing False filepath ReadWriteMode True
-	        `catchException` \e -> do c_close fd; throw e
+         -- 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.catchException` \e -> do c_close fd; throw e
 	 return (filepath, h)
       where
         filename        = prefix ++ show x ++ suffix
-- 
GitLab