-- |
-- Module : System.IO.Error
-- Copyright : (c) The University of Glasgow 2001
--- License : BSD-style (see the file libraries/core/LICENSE)
+-- License : BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer : libraries@haskell.org
-- Stability : provisional
module System.IO.Error (
IOError, -- abstract
+#ifdef __GLASGOW_HASKELL__
IOErrorType, -- abstract
+#endif
ioError, -- :: IOError -> IO a
userError, -- :: String -> IOError
+#ifdef __GLASGOW_HASKELL__
mkIOError, -- :: IOErrorType -> String -> Maybe Handle
-- -> Maybe FilePath -> IOError
isIllegalOperationErrorType,
isPermissionErrorType,
isUserErrorType,
+#endif /* __GLASGOW_HASKELL__ */
isAlreadyExistsError, -- :: IOError -> Bool
isDoesNotExistError,
isPermissionError,
isUserError,
+#ifdef __GLASGOW_HASKELL__
ioeGetErrorType, -- :: IOError -> IOErrorType
+#endif
ioeGetErrorString, -- :: IOError -> String
ioeGetHandle, -- :: IOError -> Maybe Handle
ioeGetFileName, -- :: IOError -> Maybe FilePath
import Text.Show
#endif
+#ifdef __HUGS__
+import Hugs.IO
+#endif
+
+#ifdef __NHC__
+import IO
+ ( IOError ()
+ , ioError
+ , userError
+ , isAlreadyExistsError -- :: IOError -> Bool
+ , isDoesNotExistError
+ , isAlreadyInUseError
+ , isFullError
+ , isEOFError
+ , isIllegalOperation
+ , isPermissionError
+ , isUserError
+ , ioeGetErrorString -- :: IOError -> String
+ , ioeGetHandle -- :: IOError -> Maybe Handle
+ , ioeGetFileName -- :: IOError -> Maybe FilePath
+ )
+--import Data.Maybe (fromJust)
+--import Control.Monad (MonadPlus(mplus))
+#endif
+
+#ifdef __GLASGOW_HASKELL__
-- -----------------------------------------------------------------------------
-- Constructing an IOError
ioe_handle = maybe_hdl,
ioe_filename = maybe_filename
}
+#ifdef __NHC__
+mkIOError EOF location maybe_hdl maybe_filename =
+ EOFError location (fromJust maybe_hdl)
+mkIOError UserError location maybe_hdl maybe_filename =
+ UserError location ""
+mkIOError t location maybe_hdl maybe_filename =
+ NHC.FFI.mkIOError location maybe_filename maybe_handle (ioeTypeToInt t)
+ where
+ ioeTypeToInt AlreadyExists = fromEnum EEXIST
+ ioeTypeToInt NoSuchThing = fromEnum ENOENT
+ ioeTypeToInt ResourceBusy = fromEnum EBUSY
+ ioeTypeToInt ResourceExhausted = fromEnum ENOSPC
+ ioeTypeToInt IllegalOperation = fromEnum EPERM
+ ioeTypeToInt PermissionDenied = fromEnum EACCES
+#endif
-- -----------------------------------------------------------------------------
-- IOErrorType
isIllegalOperation = isIllegalOperationErrorType . ioeGetErrorType
isPermissionError = isPermissionErrorType . ioeGetErrorType
isUserError = isUserErrorType . ioeGetErrorType
+#endif
-- -----------------------------------------------------------------------------
-- IOErrorTypes
+#ifdef __NHC__
+data IOErrorType = AlreadyExists | NoSuchThing | ResourceBusy
+ | ResourceExhausted | EOF | IllegalOperation
+ | PermissionDenied | UserError
+#endif
+
#ifdef __GLASGOW_HASKELL__
alreadyExistsErrorType, doesNotExistErrorType, alreadyInUseErrorType,
fullErrorType, eofErrorType, illegalOperationErrorType,
-- -----------------------------------------------------------------------------
-- IOErrorType predicates
+#ifdef __GLASGOW_HASKELL__
isAlreadyExistsErrorType, isDoesNotExistErrorType, isAlreadyInUseErrorType,
isFullErrorType, isEOFErrorType, isIllegalOperationErrorType,
isPermissionErrorType, isUserErrorType :: IOErrorType -> Bool
+#endif
#ifdef __GLASGOW_HASKELL__
isAlreadyExistsErrorType AlreadyExists = True
ioeGetFileName :: IOError -> Maybe FilePath
ioeGetErrorType (IOException ioe) = ioe_type ioe
-ioeGetErrorType _ = error "System.IO.Error.ioeGetHandle: not an IO error"
+ioeGetErrorType _ = error "System.IO.Error.ioeGetErrorType: not an IO error"
ioeGetHandle (IOException ioe) = ioe_handle ioe
ioeGetHandle _ = error "System.IO.Error.ioeGetHandle: not an IO error"
ioeGetErrorString (IOException ioe)
- | isUserErrorType (ioe_type ioe) = show (ioe_descr ioe)
+ | isUserErrorType (ioe_type ioe) = ioe_descr ioe
| otherwise = show (ioe_type ioe)
ioeGetErrorString _ = error "System.IO.Error.ioeGetErrorString: not an IO error"
annotateIOError exc _ _ _ =
exc
#endif
+
+#ifdef 0 /*__NHC__*/
+annotateIOError (IOError msg file hdl code) msg' file' hdl' =
+ IOError (msg++'\n':msg') (file`mplus`file') (hdl`mplus`hdl') code
+annotateIOError (EOFError msg hdl) msg' file' hdl' =
+ EOFError (msg++'\n':msg') (hdl`mplus`hdl')
+annotateIOError (UserError loc msg) msg' file' hdl' =
+ UserError loc (msg++'\n':msg')
+annotateIOError (PatternError loc) msg' file' hdl' =
+ PatternError (loc++'\n':msg')
+#endif