1 {-# OPTIONS -fno-implicit-prelude -#include "HsCore.h" #-}
2 -----------------------------------------------------------------------------
4 -- Module : Foreign.C.Error
5 -- Copyright : (c) The FFI task force 2001
6 -- License : BSD-style (see the file libraries/core/LICENSE)
8 -- Maintainer : ffi@haskell.org
9 -- Stability : provisional
10 -- Portability : portable
12 -- $Id: Error.hs,v 1.4 2001/12/21 15:07:22 simonmar Exp $
14 -- C-specific Marshalling support: Handling of C "errno" error codes
16 -----------------------------------------------------------------------------
18 module Foreign.C.Error (
20 -- Haskell representation for "errno" values
22 Errno(..), -- instance: Eq
23 eOK, e2BIG, eACCES, eADDRINUSE, eADDRNOTAVAIL, eADV, eAFNOSUPPORT, eAGAIN,
24 eALREADY, eBADF, eBADMSG, eBADRPC, eBUSY, eCHILD, eCOMM, eCONNABORTED,
25 eCONNREFUSED, eCONNRESET, eDEADLK, eDESTADDRREQ, eDIRTY, eDOM, eDQUOT,
26 eEXIST, eFAULT, eFBIG, eFTYPE, eHOSTDOWN, eHOSTUNREACH, eIDRM, eILSEQ,
27 eINPROGRESS, eINTR, eINVAL, eIO, eISCONN, eISDIR, eLOOP, eMFILE, eMLINK,
28 eMSGSIZE, eMULTIHOP, eNAMETOOLONG, eNETDOWN, eNETRESET, eNETUNREACH,
29 eNFILE, eNOBUFS, eNODATA, eNODEV, eNOENT, eNOEXEC, eNOLCK, eNOLINK,
30 eNOMEM, eNOMSG, eNONET, eNOPROTOOPT, eNOSPC, eNOSR, eNOSTR, eNOSYS,
31 eNOTBLK, eNOTCONN, eNOTDIR, eNOTEMPTY, eNOTSOCK, eNOTTY, eNXIO,
32 eOPNOTSUPP, ePERM, ePFNOSUPPORT, ePIPE, ePROCLIM, ePROCUNAVAIL,
33 ePROGMISMATCH, ePROGUNAVAIL, ePROTO, ePROTONOSUPPORT, ePROTOTYPE,
34 eRANGE, eREMCHG, eREMOTE, eROFS, eRPCMISMATCH, eRREMOTE, eSHUTDOWN,
35 eSOCKTNOSUPPORT, eSPIPE, eSRCH, eSRMNT, eSTALE, eTIME, eTIMEDOUT,
36 eTOOMANYREFS, eTXTBSY, eUSERS, eWOULDBLOCK, eXDEV,
38 isValidErrno, -- :: Errno -> Bool
40 -- access to the current thread's "errno" value
42 getErrno, -- :: IO Errno
43 resetErrno, -- :: IO ()
45 -- conversion of an "errno" value into IO error
47 errnoToIOError, -- :: String -- location
49 -- -> Maybe Handle -- handle
50 -- -> Maybe String -- filename
53 -- throw current "errno" value
55 throwErrno, -- :: String -> IO a
57 -- guards for IO operations that may fail
59 throwErrnoIf, -- :: (a -> Bool) -> String -> IO a -> IO a
60 throwErrnoIf_, -- :: (a -> Bool) -> String -> IO a -> IO ()
61 throwErrnoIfRetry, -- :: (a -> Bool) -> String -> IO a -> IO a
62 throwErrnoIfRetry_, -- :: (a -> Bool) -> String -> IO a -> IO ()
63 throwErrnoIfMinus1, -- :: Num a
64 -- => String -> IO a -> IO a
65 throwErrnoIfMinus1_, -- :: Num a
66 -- => String -> IO a -> IO ()
67 throwErrnoIfMinus1Retry,
69 -- => String -> IO a -> IO a
70 throwErrnoIfMinus1Retry_,
72 -- => String -> IO a -> IO ()
73 throwErrnoIfNull, -- :: String -> IO (Ptr a) -> IO (Ptr a)
74 throwErrnoIfNullRetry,-- :: String -> IO (Ptr a) -> IO (Ptr a)
76 throwErrnoIfRetryMayBlock,
77 throwErrnoIfRetryMayBlock_,
78 throwErrnoIfMinus1RetryMayBlock,
79 throwErrnoIfMinus1RetryMayBlock_,
80 throwErrnoIfNullRetryMayBlock
84 -- this is were we get the CCONST_XXX definitions from that configure
89 -- system dependent imports
90 -- ------------------------
92 -- GHC allows us to get at the guts inside IO errors/exceptions
94 #if __GLASGOW_HASKELL__
95 import GHC.IOBase (Exception(..), IOException(..), IOErrorType(..))
96 #endif /* __GLASGOW_HASKELL__ */
103 import Foreign.C.Types
104 import Foreign.C.String
105 import Foreign.Marshal.Error ( void )
108 #if __GLASGOW_HASKELL__
114 import System.IO ( IOError, Handle, ioError )
120 -- import of C function that gives address of errno
121 -- This function exists because errno is a variable on some systems, but on
122 -- Windows it is a macro for a function...
123 -- [yes, global variables and thread safety don't really go hand-in-hand. -- sof]
124 foreign import "ghcErrno" unsafe _errno :: Ptr CInt
126 -- Haskell representation for "errno" values
128 newtype Errno = Errno CInt
130 instance Eq Errno where
131 errno1@(Errno no1) == errno2@(Errno no2)
132 | isValidErrno errno1 && isValidErrno errno2 = no1 == no2
135 -- common "errno" symbols
137 eOK, e2BIG, eACCES, eADDRINUSE, eADDRNOTAVAIL, eADV, eAFNOSUPPORT, eAGAIN,
138 eALREADY, eBADF, eBADMSG, eBADRPC, eBUSY, eCHILD, eCOMM, eCONNABORTED,
139 eCONNREFUSED, eCONNRESET, eDEADLK, eDESTADDRREQ, eDIRTY, eDOM, eDQUOT,
140 eEXIST, eFAULT, eFBIG, eFTYPE, eHOSTDOWN, eHOSTUNREACH, eIDRM, eILSEQ,
141 eINPROGRESS, eINTR, eINVAL, eIO, eISCONN, eISDIR, eLOOP, eMFILE, eMLINK,
142 eMSGSIZE, eMULTIHOP, eNAMETOOLONG, eNETDOWN, eNETRESET, eNETUNREACH,
143 eNFILE, eNOBUFS, eNODATA, eNODEV, eNOENT, eNOEXEC, eNOLCK, eNOLINK,
144 eNOMEM, eNOMSG, eNONET, eNOPROTOOPT, eNOSPC, eNOSR, eNOSTR, eNOSYS,
145 eNOTBLK, eNOTCONN, eNOTDIR, eNOTEMPTY, eNOTSOCK, eNOTTY, eNXIO,
146 eOPNOTSUPP, ePERM, ePFNOSUPPORT, ePIPE, ePROCLIM, ePROCUNAVAIL,
147 ePROGMISMATCH, ePROGUNAVAIL, ePROTO, ePROTONOSUPPORT, ePROTOTYPE,
148 eRANGE, eREMCHG, eREMOTE, eROFS, eRPCMISMATCH, eRREMOTE, eSHUTDOWN,
149 eSOCKTNOSUPPORT, eSPIPE, eSRCH, eSRMNT, eSTALE, eTIME, eTIMEDOUT,
150 eTOOMANYREFS, eTXTBSY, eUSERS, eWOULDBLOCK, eXDEV :: Errno
152 -- the cCONST_XXX identifiers are cpp symbols whose value is computed by
156 e2BIG = Errno (cCONST_E2BIG)
157 eACCES = Errno (cCONST_EACCES)
158 eADDRINUSE = Errno (cCONST_EADDRINUSE)
159 eADDRNOTAVAIL = Errno (cCONST_EADDRNOTAVAIL)
160 eADV = Errno (cCONST_EADV)
161 eAFNOSUPPORT = Errno (cCONST_EAFNOSUPPORT)
162 eAGAIN = Errno (cCONST_EAGAIN)
163 eALREADY = Errno (cCONST_EALREADY)
164 eBADF = Errno (cCONST_EBADF)
165 eBADMSG = Errno (cCONST_EBADMSG)
166 eBADRPC = Errno (cCONST_EBADRPC)
167 eBUSY = Errno (cCONST_EBUSY)
168 eCHILD = Errno (cCONST_ECHILD)
169 eCOMM = Errno (cCONST_ECOMM)
170 eCONNABORTED = Errno (cCONST_ECONNABORTED)
171 eCONNREFUSED = Errno (cCONST_ECONNREFUSED)
172 eCONNRESET = Errno (cCONST_ECONNRESET)
173 eDEADLK = Errno (cCONST_EDEADLK)
174 eDESTADDRREQ = Errno (cCONST_EDESTADDRREQ)
175 eDIRTY = Errno (cCONST_EDIRTY)
176 eDOM = Errno (cCONST_EDOM)
177 eDQUOT = Errno (cCONST_EDQUOT)
178 eEXIST = Errno (cCONST_EEXIST)
179 eFAULT = Errno (cCONST_EFAULT)
180 eFBIG = Errno (cCONST_EFBIG)
181 eFTYPE = Errno (cCONST_EFTYPE)
182 eHOSTDOWN = Errno (cCONST_EHOSTDOWN)
183 eHOSTUNREACH = Errno (cCONST_EHOSTUNREACH)
184 eIDRM = Errno (cCONST_EIDRM)
185 eILSEQ = Errno (cCONST_EILSEQ)
186 eINPROGRESS = Errno (cCONST_EINPROGRESS)
187 eINTR = Errno (cCONST_EINTR)
188 eINVAL = Errno (cCONST_EINVAL)
189 eIO = Errno (cCONST_EIO)
190 eISCONN = Errno (cCONST_EISCONN)
191 eISDIR = Errno (cCONST_EISDIR)
192 eLOOP = Errno (cCONST_ELOOP)
193 eMFILE = Errno (cCONST_EMFILE)
194 eMLINK = Errno (cCONST_EMLINK)
195 eMSGSIZE = Errno (cCONST_EMSGSIZE)
196 eMULTIHOP = Errno (cCONST_EMULTIHOP)
197 eNAMETOOLONG = Errno (cCONST_ENAMETOOLONG)
198 eNETDOWN = Errno (cCONST_ENETDOWN)
199 eNETRESET = Errno (cCONST_ENETRESET)
200 eNETUNREACH = Errno (cCONST_ENETUNREACH)
201 eNFILE = Errno (cCONST_ENFILE)
202 eNOBUFS = Errno (cCONST_ENOBUFS)
203 eNODATA = Errno (cCONST_ENODATA)
204 eNODEV = Errno (cCONST_ENODEV)
205 eNOENT = Errno (cCONST_ENOENT)
206 eNOEXEC = Errno (cCONST_ENOEXEC)
207 eNOLCK = Errno (cCONST_ENOLCK)
208 eNOLINK = Errno (cCONST_ENOLINK)
209 eNOMEM = Errno (cCONST_ENOMEM)
210 eNOMSG = Errno (cCONST_ENOMSG)
211 eNONET = Errno (cCONST_ENONET)
212 eNOPROTOOPT = Errno (cCONST_ENOPROTOOPT)
213 eNOSPC = Errno (cCONST_ENOSPC)
214 eNOSR = Errno (cCONST_ENOSR)
215 eNOSTR = Errno (cCONST_ENOSTR)
216 eNOSYS = Errno (cCONST_ENOSYS)
217 eNOTBLK = Errno (cCONST_ENOTBLK)
218 eNOTCONN = Errno (cCONST_ENOTCONN)
219 eNOTDIR = Errno (cCONST_ENOTDIR)
220 eNOTEMPTY = Errno (cCONST_ENOTEMPTY)
221 eNOTSOCK = Errno (cCONST_ENOTSOCK)
222 eNOTTY = Errno (cCONST_ENOTTY)
223 eNXIO = Errno (cCONST_ENXIO)
224 eOPNOTSUPP = Errno (cCONST_EOPNOTSUPP)
225 ePERM = Errno (cCONST_EPERM)
226 ePFNOSUPPORT = Errno (cCONST_EPFNOSUPPORT)
227 ePIPE = Errno (cCONST_EPIPE)
228 ePROCLIM = Errno (cCONST_EPROCLIM)
229 ePROCUNAVAIL = Errno (cCONST_EPROCUNAVAIL)
230 ePROGMISMATCH = Errno (cCONST_EPROGMISMATCH)
231 ePROGUNAVAIL = Errno (cCONST_EPROGUNAVAIL)
232 ePROTO = Errno (cCONST_EPROTO)
233 ePROTONOSUPPORT = Errno (cCONST_EPROTONOSUPPORT)
234 ePROTOTYPE = Errno (cCONST_EPROTOTYPE)
235 eRANGE = Errno (cCONST_ERANGE)
236 eREMCHG = Errno (cCONST_EREMCHG)
237 eREMOTE = Errno (cCONST_EREMOTE)
238 eROFS = Errno (cCONST_EROFS)
239 eRPCMISMATCH = Errno (cCONST_ERPCMISMATCH)
240 eRREMOTE = Errno (cCONST_ERREMOTE)
241 eSHUTDOWN = Errno (cCONST_ESHUTDOWN)
242 eSOCKTNOSUPPORT = Errno (cCONST_ESOCKTNOSUPPORT)
243 eSPIPE = Errno (cCONST_ESPIPE)
244 eSRCH = Errno (cCONST_ESRCH)
245 eSRMNT = Errno (cCONST_ESRMNT)
246 eSTALE = Errno (cCONST_ESTALE)
247 eTIME = Errno (cCONST_ETIME)
248 eTIMEDOUT = Errno (cCONST_ETIMEDOUT)
249 eTOOMANYREFS = Errno (cCONST_ETOOMANYREFS)
250 eTXTBSY = Errno (cCONST_ETXTBSY)
251 eUSERS = Errno (cCONST_EUSERS)
252 eWOULDBLOCK = Errno (cCONST_EWOULDBLOCK)
253 eXDEV = Errno (cCONST_EXDEV)
255 -- checks whether the given errno value is supported on the current
258 isValidErrno :: Errno -> Bool
260 -- the configure script sets all invalid "errno"s to -1
262 isValidErrno (Errno errno) = errno /= -1
265 -- access to the current thread's "errno" value
266 -- --------------------------------------------
268 -- yield the current thread's "errno" value
271 getErrno = do e <- peek _errno; return (Errno e)
273 -- set the current thread's "errno" value to 0
276 resetErrno = poke _errno 0
279 -- throw current "errno" value
280 -- ---------------------------
282 -- the common case: throw an IO error based on a textual description
283 -- of the error location and the current thread's "errno" value
285 throwErrno :: String -> IO a
289 ioError (errnoToIOError loc errno Nothing Nothing)
292 -- guards for IO operations that may fail
293 -- --------------------------------------
295 -- guard an IO operation and throw an "errno" based exception of the result
296 -- value of the IO operation meets the given predicate
298 throwErrnoIf :: (a -> Bool) -> String -> IO a -> IO a
299 throwErrnoIf pred loc f =
302 if pred res then throwErrno loc else return res
304 -- as `throwErrnoIf', but discards the result
306 throwErrnoIf_ :: (a -> Bool) -> String -> IO a -> IO ()
307 throwErrnoIf_ pred loc f = void $ throwErrnoIf pred loc f
309 -- as `throwErrnoIf', but retries interrupted IO operations (ie, those whose
312 throwErrnoIfRetry :: (a -> Bool) -> String -> IO a -> IO a
313 throwErrnoIfRetry pred loc f =
320 then throwErrnoIfRetry pred loc f
324 -- as `throwErrnoIfRetry', but checks for operations that would block and
325 -- executes an alternative action in that case.
327 throwErrnoIfRetryMayBlock :: (a -> Bool) -> String -> IO a -> IO b -> IO a
328 throwErrnoIfRetryMayBlock pred loc f on_block =
335 then throwErrnoIfRetryMayBlock pred loc f on_block
336 else if err == eWOULDBLOCK || err == eAGAIN
337 then do on_block; throwErrnoIfRetryMayBlock pred loc f on_block
341 -- as `throwErrnoIfRetry', but discards the result
343 throwErrnoIfRetry_ :: (a -> Bool) -> String -> IO a -> IO ()
344 throwErrnoIfRetry_ pred loc f = void $ throwErrnoIfRetry pred loc f
346 -- as `throwErrnoIfRetryMayBlock', but discards the result
348 throwErrnoIfRetryMayBlock_ :: (a -> Bool) -> String -> IO a -> IO b -> IO ()
349 throwErrnoIfRetryMayBlock_ pred loc f on_block
350 = void $ throwErrnoIfRetryMayBlock pred loc f on_block
352 -- throws "errno" if a result of "-1" is returned
354 throwErrnoIfMinus1 :: Num a => String -> IO a -> IO a
355 throwErrnoIfMinus1 = throwErrnoIf (== -1)
357 -- as `throwErrnoIfMinus1', but discards the result
359 throwErrnoIfMinus1_ :: Num a => String -> IO a -> IO ()
360 throwErrnoIfMinus1_ = throwErrnoIf_ (== -1)
362 -- throws "errno" if a result of "-1" is returned, but retries in case of an
363 -- interrupted operation
365 throwErrnoIfMinus1Retry :: Num a => String -> IO a -> IO a
366 throwErrnoIfMinus1Retry = throwErrnoIfRetry (== -1)
368 -- as `throwErrnoIfMinus1', but discards the result
370 throwErrnoIfMinus1Retry_ :: Num a => String -> IO a -> IO ()
371 throwErrnoIfMinus1Retry_ = throwErrnoIfRetry_ (== -1)
373 -- as throwErrnoIfMinus1Retry, but checks for operations that would block
375 throwErrnoIfMinus1RetryMayBlock :: Num a => String -> IO a -> IO b -> IO a
376 throwErrnoIfMinus1RetryMayBlock = throwErrnoIfRetryMayBlock (== -1)
378 -- as `throwErrnoIfMinus1RetryMayBlock', but discards the result
380 throwErrnoIfMinus1RetryMayBlock_ :: Num a => String -> IO a -> IO b -> IO ()
381 throwErrnoIfMinus1RetryMayBlock_ = throwErrnoIfRetryMayBlock_ (== -1)
383 -- throws "errno" if a result of a NULL pointer is returned
385 throwErrnoIfNull :: String -> IO (Ptr a) -> IO (Ptr a)
386 throwErrnoIfNull = throwErrnoIf (== nullPtr)
388 -- throws "errno" if a result of a NULL pointer is returned, but retries in
389 -- case of an interrupted operation
391 throwErrnoIfNullRetry :: String -> IO (Ptr a) -> IO (Ptr a)
392 throwErrnoIfNullRetry = throwErrnoIfRetry (== nullPtr)
394 -- as throwErrnoIfNullRetry, but checks for operations that would block
396 throwErrnoIfNullRetryMayBlock :: String -> IO (Ptr a) -> IO b -> IO (Ptr a)
397 throwErrnoIfNullRetryMayBlock = throwErrnoIfRetryMayBlock (== nullPtr)
399 -- conversion of an "errno" value into IO error
400 -- --------------------------------------------
402 -- convert a location string, an "errno" value, an optional handle,
403 -- and an optional filename into a matching IO error
405 errnoToIOError :: String -> Errno -> Maybe Handle -> Maybe String -> IOError
406 errnoToIOError loc errno maybeHdl maybeName = unsafePerformIO $ do
407 str <- strerror errno >>= peekCString
408 #if __GLASGOW_HASKELL__
409 return (IOException (IOError maybeHdl errType loc str maybeName))
412 | errno == eOK = OtherError
413 | errno == e2BIG = ResourceExhausted
414 | errno == eACCES = PermissionDenied
415 | errno == eADDRINUSE = ResourceBusy
416 | errno == eADDRNOTAVAIL = UnsupportedOperation
417 | errno == eADV = OtherError
418 | errno == eAFNOSUPPORT = UnsupportedOperation
419 | errno == eAGAIN = ResourceExhausted
420 | errno == eALREADY = AlreadyExists
421 | errno == eBADF = OtherError
422 | errno == eBADMSG = InappropriateType
423 | errno == eBADRPC = OtherError
424 | errno == eBUSY = ResourceBusy
425 | errno == eCHILD = NoSuchThing
426 | errno == eCOMM = ResourceVanished
427 | errno == eCONNABORTED = OtherError
428 | errno == eCONNREFUSED = NoSuchThing
429 | errno == eCONNRESET = ResourceVanished
430 | errno == eDEADLK = ResourceBusy
431 | errno == eDESTADDRREQ = InvalidArgument
432 | errno == eDIRTY = UnsatisfiedConstraints
433 | errno == eDOM = InvalidArgument
434 | errno == eDQUOT = PermissionDenied
435 | errno == eEXIST = AlreadyExists
436 | errno == eFAULT = OtherError
437 | errno == eFBIG = PermissionDenied
438 | errno == eFTYPE = InappropriateType
439 | errno == eHOSTDOWN = NoSuchThing
440 | errno == eHOSTUNREACH = NoSuchThing
441 | errno == eIDRM = ResourceVanished
442 | errno == eILSEQ = InvalidArgument
443 | errno == eINPROGRESS = AlreadyExists
444 | errno == eINTR = Interrupted
445 | errno == eINVAL = InvalidArgument
446 | errno == eIO = HardwareFault
447 | errno == eISCONN = AlreadyExists
448 | errno == eISDIR = InappropriateType
449 | errno == eLOOP = InvalidArgument
450 | errno == eMFILE = ResourceExhausted
451 | errno == eMLINK = ResourceExhausted
452 | errno == eMSGSIZE = ResourceExhausted
453 | errno == eMULTIHOP = UnsupportedOperation
454 | errno == eNAMETOOLONG = InvalidArgument
455 | errno == eNETDOWN = ResourceVanished
456 | errno == eNETRESET = ResourceVanished
457 | errno == eNETUNREACH = NoSuchThing
458 | errno == eNFILE = ResourceExhausted
459 | errno == eNOBUFS = ResourceExhausted
460 | errno == eNODATA = NoSuchThing
461 | errno == eNODEV = UnsupportedOperation
462 | errno == eNOENT = NoSuchThing
463 | errno == eNOEXEC = InvalidArgument
464 | errno == eNOLCK = ResourceExhausted
465 | errno == eNOLINK = ResourceVanished
466 | errno == eNOMEM = ResourceExhausted
467 | errno == eNOMSG = NoSuchThing
468 | errno == eNONET = NoSuchThing
469 | errno == eNOPROTOOPT = UnsupportedOperation
470 | errno == eNOSPC = ResourceExhausted
471 | errno == eNOSR = ResourceExhausted
472 | errno == eNOSTR = InvalidArgument
473 | errno == eNOSYS = UnsupportedOperation
474 | errno == eNOTBLK = InvalidArgument
475 | errno == eNOTCONN = InvalidArgument
476 | errno == eNOTDIR = InappropriateType
477 | errno == eNOTEMPTY = UnsatisfiedConstraints
478 | errno == eNOTSOCK = InvalidArgument
479 | errno == eNOTTY = IllegalOperation
480 | errno == eNXIO = NoSuchThing
481 | errno == eOPNOTSUPP = UnsupportedOperation
482 | errno == ePERM = PermissionDenied
483 | errno == ePFNOSUPPORT = UnsupportedOperation
484 | errno == ePIPE = ResourceVanished
485 | errno == ePROCLIM = PermissionDenied
486 | errno == ePROCUNAVAIL = UnsupportedOperation
487 | errno == ePROGMISMATCH = ProtocolError
488 | errno == ePROGUNAVAIL = UnsupportedOperation
489 | errno == ePROTO = ProtocolError
490 | errno == ePROTONOSUPPORT = ProtocolError
491 | errno == ePROTOTYPE = ProtocolError
492 | errno == eRANGE = UnsupportedOperation
493 | errno == eREMCHG = ResourceVanished
494 | errno == eREMOTE = IllegalOperation
495 | errno == eROFS = PermissionDenied
496 | errno == eRPCMISMATCH = ProtocolError
497 | errno == eRREMOTE = IllegalOperation
498 | errno == eSHUTDOWN = IllegalOperation
499 | errno == eSOCKTNOSUPPORT = UnsupportedOperation
500 | errno == eSPIPE = UnsupportedOperation
501 | errno == eSRCH = NoSuchThing
502 | errno == eSRMNT = UnsatisfiedConstraints
503 | errno == eSTALE = ResourceVanished
504 | errno == eTIME = TimeExpired
505 | errno == eTIMEDOUT = TimeExpired
506 | errno == eTOOMANYREFS = ResourceExhausted
507 | errno == eTXTBSY = ResourceBusy
508 | errno == eUSERS = ResourceExhausted
509 | errno == eWOULDBLOCK = OtherError
510 | errno == eXDEV = UnsupportedOperation
511 | otherwise = OtherError
513 return (userError (loc ++ ": " ++ str ++ maybe "" (": "++) maybeName))
516 foreign import unsafe strerror :: Errno -> IO (Ptr CChar)
519 -- Dreadfully tedious callouts to wrappers which define the
520 -- actual values for the error codes.
521 foreign import ccall "prel_error_E2BIG" unsafe cCONST_E2BIG :: CInt
522 foreign import ccall "prel_error_EACCES" unsafe cCONST_EACCES :: CInt
523 foreign import ccall "prel_error_EADDRINUSE" unsafe cCONST_EADDRINUSE :: CInt
524 foreign import ccall "prel_error_EADDRNOTAVAIL" unsafe cCONST_EADDRNOTAVAIL :: CInt
525 foreign import ccall "prel_error_EADV" unsafe cCONST_EADV :: CInt
526 foreign import ccall "prel_error_EAFNOSUPPORT" unsafe cCONST_EAFNOSUPPORT :: CInt
527 foreign import ccall "prel_error_EAGAIN" unsafe cCONST_EAGAIN :: CInt
528 foreign import ccall "prel_error_EALREADY" unsafe cCONST_EALREADY :: CInt
529 foreign import ccall "prel_error_EBADF" unsafe cCONST_EBADF :: CInt
530 foreign import ccall "prel_error_EBADMSG" unsafe cCONST_EBADMSG :: CInt
531 foreign import ccall "prel_error_EBADRPC" unsafe cCONST_EBADRPC :: CInt
532 foreign import ccall "prel_error_EBUSY" unsafe cCONST_EBUSY :: CInt
533 foreign import ccall "prel_error_ECHILD" unsafe cCONST_ECHILD :: CInt
534 foreign import ccall "prel_error_ECOMM" unsafe cCONST_ECOMM :: CInt
535 foreign import ccall "prel_error_ECONNABORTED" unsafe cCONST_ECONNABORTED :: CInt
536 foreign import ccall "prel_error_ECONNREFUSED" unsafe cCONST_ECONNREFUSED :: CInt
537 foreign import ccall "prel_error_ECONNRESET" unsafe cCONST_ECONNRESET :: CInt
538 foreign import ccall "prel_error_EDEADLK" unsafe cCONST_EDEADLK :: CInt
539 foreign import ccall "prel_error_EDESTADDRREQ" unsafe cCONST_EDESTADDRREQ :: CInt
540 foreign import ccall "prel_error_EDIRTY" unsafe cCONST_EDIRTY :: CInt
541 foreign import ccall "prel_error_EDOM" unsafe cCONST_EDOM :: CInt
542 foreign import ccall "prel_error_EDQUOT" unsafe cCONST_EDQUOT :: CInt
543 foreign import ccall "prel_error_EEXIST" unsafe cCONST_EEXIST :: CInt
544 foreign import ccall "prel_error_EFAULT" unsafe cCONST_EFAULT :: CInt
545 foreign import ccall "prel_error_EFBIG" unsafe cCONST_EFBIG :: CInt
546 foreign import ccall "prel_error_EFTYPE" unsafe cCONST_EFTYPE :: CInt
547 foreign import ccall "prel_error_EHOSTDOWN" unsafe cCONST_EHOSTDOWN :: CInt
548 foreign import ccall "prel_error_EHOSTUNREACH" unsafe cCONST_EHOSTUNREACH :: CInt
549 foreign import ccall "prel_error_EIDRM" unsafe cCONST_EIDRM :: CInt
550 foreign import ccall "prel_error_EILSEQ" unsafe cCONST_EILSEQ :: CInt
551 foreign import ccall "prel_error_EINPROGRESS" unsafe cCONST_EINPROGRESS :: CInt
552 foreign import ccall "prel_error_EINTR" unsafe cCONST_EINTR :: CInt
553 foreign import ccall "prel_error_EINVAL" unsafe cCONST_EINVAL :: CInt
554 foreign import ccall "prel_error_EIO" unsafe cCONST_EIO :: CInt
555 foreign import ccall "prel_error_EISCONN" unsafe cCONST_EISCONN :: CInt
556 foreign import ccall "prel_error_EISDIR" unsafe cCONST_EISDIR :: CInt
557 foreign import ccall "prel_error_ELOOP" unsafe cCONST_ELOOP :: CInt
558 foreign import ccall "prel_error_EMFILE" unsafe cCONST_EMFILE :: CInt
559 foreign import ccall "prel_error_EMLINK" unsafe cCONST_EMLINK :: CInt
560 foreign import ccall "prel_error_EMSGSIZE" unsafe cCONST_EMSGSIZE :: CInt
561 foreign import ccall "prel_error_EMULTIHOP" unsafe cCONST_EMULTIHOP :: CInt
562 foreign import ccall "prel_error_ENAMETOOLONG" unsafe cCONST_ENAMETOOLONG :: CInt
563 foreign import ccall "prel_error_ENETDOWN" unsafe cCONST_ENETDOWN :: CInt
564 foreign import ccall "prel_error_ENETRESET" unsafe cCONST_ENETRESET :: CInt
565 foreign import ccall "prel_error_ENETUNREACH" unsafe cCONST_ENETUNREACH :: CInt
566 foreign import ccall "prel_error_ENFILE" unsafe cCONST_ENFILE :: CInt
567 foreign import ccall "prel_error_ENOBUFS" unsafe cCONST_ENOBUFS :: CInt
568 foreign import ccall "prel_error_ENODATA" unsafe cCONST_ENODATA :: CInt
569 foreign import ccall "prel_error_ENODEV" unsafe cCONST_ENODEV :: CInt
570 foreign import ccall "prel_error_ENOENT" unsafe cCONST_ENOENT :: CInt
571 foreign import ccall "prel_error_ENOEXEC" unsafe cCONST_ENOEXEC :: CInt
572 foreign import ccall "prel_error_ENOLCK" unsafe cCONST_ENOLCK :: CInt
573 foreign import ccall "prel_error_ENOLINK" unsafe cCONST_ENOLINK :: CInt
574 foreign import ccall "prel_error_ENOMEM" unsafe cCONST_ENOMEM :: CInt
575 foreign import ccall "prel_error_ENOMSG" unsafe cCONST_ENOMSG :: CInt
576 foreign import ccall "prel_error_ENONET" unsafe cCONST_ENONET :: CInt
577 foreign import ccall "prel_error_ENOPROTOOPT" unsafe cCONST_ENOPROTOOPT :: CInt
578 foreign import ccall "prel_error_ENOSPC" unsafe cCONST_ENOSPC :: CInt
579 foreign import ccall "prel_error_ENOSR" unsafe cCONST_ENOSR :: CInt
580 foreign import ccall "prel_error_ENOSTR" unsafe cCONST_ENOSTR :: CInt
581 foreign import ccall "prel_error_ENOSYS" unsafe cCONST_ENOSYS :: CInt
582 foreign import ccall "prel_error_ENOTBLK" unsafe cCONST_ENOTBLK :: CInt
583 foreign import ccall "prel_error_ENOTCONN" unsafe cCONST_ENOTCONN :: CInt
584 foreign import ccall "prel_error_ENOTDIR" unsafe cCONST_ENOTDIR :: CInt
585 foreign import ccall "prel_error_ENOTEMPTY" unsafe cCONST_ENOTEMPTY :: CInt
586 foreign import ccall "prel_error_ENOTSOCK" unsafe cCONST_ENOTSOCK :: CInt
587 foreign import ccall "prel_error_ENOTTY" unsafe cCONST_ENOTTY :: CInt
588 foreign import ccall "prel_error_ENXIO" unsafe cCONST_ENXIO :: CInt
589 foreign import ccall "prel_error_EOPNOTSUPP" unsafe cCONST_EOPNOTSUPP :: CInt
590 foreign import ccall "prel_error_EPERM" unsafe cCONST_EPERM :: CInt
591 foreign import ccall "prel_error_EPFNOSUPPORT" unsafe cCONST_EPFNOSUPPORT :: CInt
592 foreign import ccall "prel_error_EPIPE" unsafe cCONST_EPIPE :: CInt
593 foreign import ccall "prel_error_EPROCLIM" unsafe cCONST_EPROCLIM :: CInt
594 foreign import ccall "prel_error_EPROCUNAVAIL" unsafe cCONST_EPROCUNAVAIL :: CInt
595 foreign import ccall "prel_error_EPROGMISMATCH" unsafe cCONST_EPROGMISMATCH :: CInt
596 foreign import ccall "prel_error_EPROGUNAVAIL" unsafe cCONST_EPROGUNAVAIL :: CInt
597 foreign import ccall "prel_error_EPROTO" unsafe cCONST_EPROTO :: CInt
598 foreign import ccall "prel_error_EPROTONOSUPPORT" unsafe cCONST_EPROTONOSUPPORT :: CInt
599 foreign import ccall "prel_error_EPROTOTYPE" unsafe cCONST_EPROTOTYPE :: CInt
600 foreign import ccall "prel_error_ERANGE" unsafe cCONST_ERANGE :: CInt
601 foreign import ccall "prel_error_EREMCHG" unsafe cCONST_EREMCHG :: CInt
602 foreign import ccall "prel_error_EREMOTE" unsafe cCONST_EREMOTE :: CInt
603 foreign import ccall "prel_error_EROFS" unsafe cCONST_EROFS :: CInt
604 foreign import ccall "prel_error_ERPCMISMATCH" unsafe cCONST_ERPCMISMATCH :: CInt
605 foreign import ccall "prel_error_ERREMOTE" unsafe cCONST_ERREMOTE :: CInt
606 foreign import ccall "prel_error_ESHUTDOWN" unsafe cCONST_ESHUTDOWN :: CInt
607 foreign import ccall "prel_error_ESOCKTNOSUPPORT" unsafe cCONST_ESOCKTNOSUPPORT :: CInt
608 foreign import ccall "prel_error_ESPIPE" unsafe cCONST_ESPIPE :: CInt
609 foreign import ccall "prel_error_ESRCH" unsafe cCONST_ESRCH :: CInt
610 foreign import ccall "prel_error_ESRMNT" unsafe cCONST_ESRMNT :: CInt
611 foreign import ccall "prel_error_ESTALE" unsafe cCONST_ESTALE :: CInt
612 foreign import ccall "prel_error_ETIME" unsafe cCONST_ETIME :: CInt
613 foreign import ccall "prel_error_ETIMEDOUT" unsafe cCONST_ETIMEDOUT :: CInt
614 foreign import ccall "prel_error_ETOOMANYREFS" unsafe cCONST_ETOOMANYREFS :: CInt
615 foreign import ccall "prel_error_ETXTBSY" unsafe cCONST_ETXTBSY :: CInt
616 foreign import ccall "prel_error_EUSERS" unsafe cCONST_EUSERS :: CInt
617 foreign import ccall "prel_error_EWOULDBLOCK" unsafe cCONST_EWOULDBLOCK :: CInt
618 foreign import ccall "prel_error_EXDEV" unsafe cCONST_EXDEV :: CInt