From: simonmar Date: Mon, 31 Mar 2003 13:58:03 +0000 (+0000) Subject: [project @ 2003-03-31 13:58:03 by simonmar] X-Git-Tag: nhc98-1-18-release~710 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=9af2914a8114a7858e370392b7704f00957fa5c2;p=ghc-base.git [project @ 2003-03-31 13:58:03 by simonmar] - Add ioeSet{ErrorType,ErrorString,Handle,FileName} to match the existing ioeGet* functions. - Add modifyIOError :: (IOError -> IOError) -> IO a -> IO a --- diff --git a/System/IO/Error.hs b/System/IO/Error.hs index a5296cc..6874ac9 100644 --- a/System/IO/Error.hs +++ b/System/IO/Error.hs @@ -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