[project @ 2003-03-31 13:58:03 by simonmar]
authorsimonmar <unknown>
Mon, 31 Mar 2003 13:58:03 +0000 (13:58 +0000)
committersimonmar <unknown>
Mon, 31 Mar 2003 13:58:03 +0000 (13:58 +0000)
- Add ioeSet{ErrorType,ErrorString,Handle,FileName} to match the
  existing ioeGet* functions.

- Add modifyIOError :: (IOError -> IOError) -> IO a -> IO a

System/IO/Error.hs

index a5296cc..6874ac9 100644 (file)
@@ -30,6 +30,8 @@ module System.IO.Error (
 
     annotateIOError,           -- :: IOError -> String -> Maybe Handle
                                --    -> Maybe FilePath -> IOError
+
+    modifyIOError,             -- :: (IOError -> IOError) -> IO a -> IO a
 #endif
 
     alreadyExistsErrorType,    -- :: IOErrorType
@@ -66,6 +68,12 @@ module System.IO.Error (
     ioeGetHandle,              -- :: IOError -> Maybe Handle
     ioeGetFileName,            -- :: IOError -> Maybe FilePath
 
+#ifndef __NHC__
+    ioeSetErrorType,           -- :: IOError -> IOErrorType -> IOError
+    ioeSetErrorString,         -- :: IOError -> String -> IOError
+    ioeSetHandle,              -- :: IOError -> Handle -> IOError
+    ioeSetFileName,            -- :: IOError -> FilePath -> IOError
+#endif
   ) where
 
 import Data.Either
@@ -221,20 +229,33 @@ isUserErrorType _ = False
 
 #if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
 ioeGetErrorType              :: IOError -> IOErrorType
-ioeGetHandle          :: IOError -> Maybe Handle
 ioeGetErrorString     :: IOError -> String
+ioeGetHandle          :: IOError -> Maybe Handle
 ioeGetFileName        :: IOError -> Maybe FilePath
 
 ioeGetErrorType ioe = ioe_type ioe
 
-ioeGetHandle ioe = ioe_handle ioe
-
 ioeGetErrorString ioe
    | isUserErrorType (ioe_type ioe) = ioe_description ioe
    | otherwise                      = show (ioe_type ioe)
 
+ioeGetHandle ioe = ioe_handle ioe
+
 ioeGetFileName ioe = ioe_filename ioe
 
+ioeSetErrorType                :: IOError -> IOErrorType -> IOError
+ioeSetErrorString      :: IOError -> String      -> IOError
+ioeSetHandle           :: IOError -> Handle      -> IOError
+ioeSetFileName         :: IOError -> FilePath    -> IOError
+
+ioeSetErrorType   ioe errtype  = ioe{ ioe_type = errtype }
+ioeSetErrorString ioe str      = ioe{ ioe_description = str }
+ioeSetHandle      ioe hdl      = ioe{ ioe_handle = Just hdl }
+ioeSetFileName    ioe filename = ioe{ ioe_filename = Just filename }
+
+modifyIOError :: (IOError -> IOError) -> IO a -> IO a
+modifyIOError f io = GHC.Exception.catch io (\e -> ioError (f e))
+
 -- -----------------------------------------------------------------------------
 -- annotating an IOError