1 {-# OPTIONS_GHC -fno-implicit-prelude -#include "HsBase.h" #-}
2 -----------------------------------------------------------------------------
4 -- Module : Foreign.C.Error
5 -- Copyright : (c) The FFI task force 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
8 -- Maintainer : ffi@haskell.org
9 -- Stability : provisional
10 -- Portability : portable
12 -- C-specific Marshalling support: Handling of C \"errno\" error codes.
14 -----------------------------------------------------------------------------
16 module Foreign.C.Error (
18 -- * Haskell representations of @errno@ values
20 Errno(..), -- instance: Eq
22 -- ** Common @errno@ symbols
23 -- | Different operating systems and\/or C libraries often support
24 -- different values of @errno@. This module defines the common values,
25 -- but due to the open definition of 'Errno' users may add definitions
26 -- which are not predefined.
27 eOK, e2BIG, eACCES, eADDRINUSE, eADDRNOTAVAIL, eADV, eAFNOSUPPORT, eAGAIN,
28 eALREADY, eBADF, eBADMSG, eBADRPC, eBUSY, eCHILD, eCOMM, eCONNABORTED,
29 eCONNREFUSED, eCONNRESET, eDEADLK, eDESTADDRREQ, eDIRTY, eDOM, eDQUOT,
30 eEXIST, eFAULT, eFBIG, eFTYPE, eHOSTDOWN, eHOSTUNREACH, eIDRM, eILSEQ,
31 eINPROGRESS, eINTR, eINVAL, eIO, eISCONN, eISDIR, eLOOP, eMFILE, eMLINK,
32 eMSGSIZE, eMULTIHOP, eNAMETOOLONG, eNETDOWN, eNETRESET, eNETUNREACH,
33 eNFILE, eNOBUFS, eNODATA, eNODEV, eNOENT, eNOEXEC, eNOLCK, eNOLINK,
34 eNOMEM, eNOMSG, eNONET, eNOPROTOOPT, eNOSPC, eNOSR, eNOSTR, eNOSYS,
35 eNOTBLK, eNOTCONN, eNOTDIR, eNOTEMPTY, eNOTSOCK, eNOTTY, eNXIO,
36 eOPNOTSUPP, ePERM, ePFNOSUPPORT, ePIPE, ePROCLIM, ePROCUNAVAIL,
37 ePROGMISMATCH, ePROGUNAVAIL, ePROTO, ePROTONOSUPPORT, ePROTOTYPE,
38 eRANGE, eREMCHG, eREMOTE, eROFS, eRPCMISMATCH, eRREMOTE, eSHUTDOWN,
39 eSOCKTNOSUPPORT, eSPIPE, eSRCH, eSRMNT, eSTALE, eTIME, eTIMEDOUT,
40 eTOOMANYREFS, eTXTBSY, eUSERS, eWOULDBLOCK, eXDEV,
42 -- ** 'Errno' functions
44 isValidErrno, -- :: Errno -> Bool
46 -- access to the current thread's "errno" value
48 getErrno, -- :: IO Errno
49 resetErrno, -- :: IO ()
51 -- conversion of an "errno" value into IO error
53 errnoToIOError, -- :: String -- location
55 -- -> Maybe Handle -- handle
56 -- -> Maybe String -- filename
59 -- throw current "errno" value
61 throwErrno, -- :: String -> IO a
63 -- ** Guards for IO operations that may fail
65 throwErrnoIf, -- :: (a -> Bool) -> String -> IO a -> IO a
66 throwErrnoIf_, -- :: (a -> Bool) -> String -> IO a -> IO ()
67 throwErrnoIfRetry, -- :: (a -> Bool) -> String -> IO a -> IO a
68 throwErrnoIfRetry_, -- :: (a -> Bool) -> String -> IO a -> IO ()
69 throwErrnoIfMinus1, -- :: Num a
70 -- => String -> IO a -> IO a
71 throwErrnoIfMinus1_, -- :: Num a
72 -- => String -> IO a -> IO ()
73 throwErrnoIfMinus1Retry,
75 -- => String -> IO a -> IO a
76 throwErrnoIfMinus1Retry_,
78 -- => String -> IO a -> IO ()
79 throwErrnoIfNull, -- :: String -> IO (Ptr a) -> IO (Ptr a)
80 throwErrnoIfNullRetry,-- :: String -> IO (Ptr a) -> IO (Ptr a)
82 throwErrnoIfRetryMayBlock,
83 throwErrnoIfRetryMayBlock_,
84 throwErrnoIfMinus1RetryMayBlock,
85 throwErrnoIfMinus1RetryMayBlock_,
86 throwErrnoIfNullRetryMayBlock
90 -- this is were we get the CONST_XXX definitions from that configure
94 #include "HsBaseConfig.h"
97 -- system dependent imports
98 -- ------------------------
100 -- GHC allows us to get at the guts inside IO errors/exceptions
102 #if __GLASGOW_HASKELL__
103 import GHC.IOBase (IOException(..), IOErrorType(..))
104 #endif /* __GLASGOW_HASKELL__ */
110 import Foreign.Storable
112 import Foreign.C.Types
113 import Foreign.C.String
114 import Foreign.Marshal.Error ( void )
117 #if __GLASGOW_HASKELL__
122 import Hugs.Prelude ( Handle, IOError, ioError )
123 import System.IO.Unsafe ( unsafePerformIO )
125 import System.IO ( Handle )
126 import System.IO.Error ( IOError, ioError )
127 import System.IO.Unsafe ( unsafePerformIO )
131 {-# CFILES cbits/PrelIOUtils.c #-}
138 -- | Haskell representation for @errno@ values.
139 -- The implementation is deliberately exposed, to allow users to add
140 -- their own definitions of 'Errno' values.
142 newtype Errno = Errno CInt
144 instance Eq Errno where
145 errno1@(Errno no1) == errno2@(Errno no2)
146 | isValidErrno errno1 && isValidErrno errno2 = no1 == no2
149 -- common "errno" symbols
151 eOK, e2BIG, eACCES, eADDRINUSE, eADDRNOTAVAIL, eADV, eAFNOSUPPORT, eAGAIN,
152 eALREADY, eBADF, eBADMSG, eBADRPC, eBUSY, eCHILD, eCOMM, eCONNABORTED,
153 eCONNREFUSED, eCONNRESET, eDEADLK, eDESTADDRREQ, eDIRTY, eDOM, eDQUOT,
154 eEXIST, eFAULT, eFBIG, eFTYPE, eHOSTDOWN, eHOSTUNREACH, eIDRM, eILSEQ,
155 eINPROGRESS, eINTR, eINVAL, eIO, eISCONN, eISDIR, eLOOP, eMFILE, eMLINK,
156 eMSGSIZE, eMULTIHOP, eNAMETOOLONG, eNETDOWN, eNETRESET, eNETUNREACH,
157 eNFILE, eNOBUFS, eNODATA, eNODEV, eNOENT, eNOEXEC, eNOLCK, eNOLINK,
158 eNOMEM, eNOMSG, eNONET, eNOPROTOOPT, eNOSPC, eNOSR, eNOSTR, eNOSYS,
159 eNOTBLK, eNOTCONN, eNOTDIR, eNOTEMPTY, eNOTSOCK, eNOTTY, eNXIO,
160 eOPNOTSUPP, ePERM, ePFNOSUPPORT, ePIPE, ePROCLIM, ePROCUNAVAIL,
161 ePROGMISMATCH, ePROGUNAVAIL, ePROTO, ePROTONOSUPPORT, ePROTOTYPE,
162 eRANGE, eREMCHG, eREMOTE, eROFS, eRPCMISMATCH, eRREMOTE, eSHUTDOWN,
163 eSOCKTNOSUPPORT, eSPIPE, eSRCH, eSRMNT, eSTALE, eTIME, eTIMEDOUT,
164 eTOOMANYREFS, eTXTBSY, eUSERS, eWOULDBLOCK, eXDEV :: Errno
166 -- the cCONST_XXX identifiers are cpp symbols whose value is computed by
173 e2BIG = Errno (CONST_E2BIG)
174 eACCES = Errno (CONST_EACCES)
175 eADDRINUSE = Errno (CONST_EADDRINUSE)
176 eADDRNOTAVAIL = Errno (CONST_EADDRNOTAVAIL)
177 eADV = Errno (CONST_EADV)
178 eAFNOSUPPORT = Errno (CONST_EAFNOSUPPORT)
179 eAGAIN = Errno (CONST_EAGAIN)
180 eALREADY = Errno (CONST_EALREADY)
181 eBADF = Errno (CONST_EBADF)
182 eBADMSG = Errno (CONST_EBADMSG)
183 eBADRPC = Errno (CONST_EBADRPC)
184 eBUSY = Errno (CONST_EBUSY)
185 eCHILD = Errno (CONST_ECHILD)
186 eCOMM = Errno (CONST_ECOMM)
187 eCONNABORTED = Errno (CONST_ECONNABORTED)
188 eCONNREFUSED = Errno (CONST_ECONNREFUSED)
189 eCONNRESET = Errno (CONST_ECONNRESET)
190 eDEADLK = Errno (CONST_EDEADLK)
191 eDESTADDRREQ = Errno (CONST_EDESTADDRREQ)
192 eDIRTY = Errno (CONST_EDIRTY)
193 eDOM = Errno (CONST_EDOM)
194 eDQUOT = Errno (CONST_EDQUOT)
195 eEXIST = Errno (CONST_EEXIST)
196 eFAULT = Errno (CONST_EFAULT)
197 eFBIG = Errno (CONST_EFBIG)
198 eFTYPE = Errno (CONST_EFTYPE)
199 eHOSTDOWN = Errno (CONST_EHOSTDOWN)
200 eHOSTUNREACH = Errno (CONST_EHOSTUNREACH)
201 eIDRM = Errno (CONST_EIDRM)
202 eILSEQ = Errno (CONST_EILSEQ)
203 eINPROGRESS = Errno (CONST_EINPROGRESS)
204 eINTR = Errno (CONST_EINTR)
205 eINVAL = Errno (CONST_EINVAL)
206 eIO = Errno (CONST_EIO)
207 eISCONN = Errno (CONST_EISCONN)
208 eISDIR = Errno (CONST_EISDIR)
209 eLOOP = Errno (CONST_ELOOP)
210 eMFILE = Errno (CONST_EMFILE)
211 eMLINK = Errno (CONST_EMLINK)
212 eMSGSIZE = Errno (CONST_EMSGSIZE)
213 eMULTIHOP = Errno (CONST_EMULTIHOP)
214 eNAMETOOLONG = Errno (CONST_ENAMETOOLONG)
215 eNETDOWN = Errno (CONST_ENETDOWN)
216 eNETRESET = Errno (CONST_ENETRESET)
217 eNETUNREACH = Errno (CONST_ENETUNREACH)
218 eNFILE = Errno (CONST_ENFILE)
219 eNOBUFS = Errno (CONST_ENOBUFS)
220 eNODATA = Errno (CONST_ENODATA)
221 eNODEV = Errno (CONST_ENODEV)
222 eNOENT = Errno (CONST_ENOENT)
223 eNOEXEC = Errno (CONST_ENOEXEC)
224 eNOLCK = Errno (CONST_ENOLCK)
225 eNOLINK = Errno (CONST_ENOLINK)
226 eNOMEM = Errno (CONST_ENOMEM)
227 eNOMSG = Errno (CONST_ENOMSG)
228 eNONET = Errno (CONST_ENONET)
229 eNOPROTOOPT = Errno (CONST_ENOPROTOOPT)
230 eNOSPC = Errno (CONST_ENOSPC)
231 eNOSR = Errno (CONST_ENOSR)
232 eNOSTR = Errno (CONST_ENOSTR)
233 eNOSYS = Errno (CONST_ENOSYS)
234 eNOTBLK = Errno (CONST_ENOTBLK)
235 eNOTCONN = Errno (CONST_ENOTCONN)
236 eNOTDIR = Errno (CONST_ENOTDIR)
237 eNOTEMPTY = Errno (CONST_ENOTEMPTY)
238 eNOTSOCK = Errno (CONST_ENOTSOCK)
239 eNOTTY = Errno (CONST_ENOTTY)
240 eNXIO = Errno (CONST_ENXIO)
241 eOPNOTSUPP = Errno (CONST_EOPNOTSUPP)
242 ePERM = Errno (CONST_EPERM)
243 ePFNOSUPPORT = Errno (CONST_EPFNOSUPPORT)
244 ePIPE = Errno (CONST_EPIPE)
245 ePROCLIM = Errno (CONST_EPROCLIM)
246 ePROCUNAVAIL = Errno (CONST_EPROCUNAVAIL)
247 ePROGMISMATCH = Errno (CONST_EPROGMISMATCH)
248 ePROGUNAVAIL = Errno (CONST_EPROGUNAVAIL)
249 ePROTO = Errno (CONST_EPROTO)
250 ePROTONOSUPPORT = Errno (CONST_EPROTONOSUPPORT)
251 ePROTOTYPE = Errno (CONST_EPROTOTYPE)
252 eRANGE = Errno (CONST_ERANGE)
253 eREMCHG = Errno (CONST_EREMCHG)
254 eREMOTE = Errno (CONST_EREMOTE)
255 eROFS = Errno (CONST_EROFS)
256 eRPCMISMATCH = Errno (CONST_ERPCMISMATCH)
257 eRREMOTE = Errno (CONST_ERREMOTE)
258 eSHUTDOWN = Errno (CONST_ESHUTDOWN)
259 eSOCKTNOSUPPORT = Errno (CONST_ESOCKTNOSUPPORT)
260 eSPIPE = Errno (CONST_ESPIPE)
261 eSRCH = Errno (CONST_ESRCH)
262 eSRMNT = Errno (CONST_ESRMNT)
263 eSTALE = Errno (CONST_ESTALE)
264 eTIME = Errno (CONST_ETIME)
265 eTIMEDOUT = Errno (CONST_ETIMEDOUT)
266 eTOOMANYREFS = Errno (CONST_ETOOMANYREFS)
267 eTXTBSY = Errno (CONST_ETXTBSY)
268 eUSERS = Errno (CONST_EUSERS)
269 eWOULDBLOCK = Errno (CONST_EWOULDBLOCK)
270 eXDEV = Errno (CONST_EXDEV)
273 -- | Yield 'True' if the given 'Errno' value is valid on the system.
274 -- This implies that the 'Eq' instance of 'Errno' is also system dependent
275 -- as it is only defined for valid values of 'Errno'.
277 isValidErrno :: Errno -> Bool
279 -- the configure script sets all invalid "errno"s to -1
281 isValidErrno (Errno errno) = errno /= -1
284 -- access to the current thread's "errno" value
285 -- --------------------------------------------
287 -- | Get the current value of @errno@ in the current thread.
291 -- We must call a C function to get the value of errno in general. On
292 -- threaded systems, errno is hidden behind a C macro so that each OS
293 -- thread gets its own copy.
295 getErrno = do e <- peek _errno; return (Errno e)
296 foreign import ccall unsafe "errno.h &errno" _errno :: Ptr CInt
298 getErrno = do e <- get_errno; return (Errno e)
299 foreign import ccall unsafe "HsBase.h __hscore_get_errno" get_errno :: IO CInt
302 -- | Reset the current thread\'s @errno@ value to 'eOK'.
306 -- Again, setting errno has to be done via a C function.
308 resetErrno = poke _errno 0
310 resetErrno = set_errno 0
311 foreign import ccall unsafe "HsBase.h __hscore_set_errno" set_errno :: CInt -> IO ()
314 -- throw current "errno" value
315 -- ---------------------------
317 -- | Throw an 'IOError' corresponding to the current value of 'getErrno'.
319 throwErrno :: String -- ^ textual description of the error location
324 ioError (errnoToIOError loc errno Nothing Nothing)
327 -- guards for IO operations that may fail
328 -- --------------------------------------
330 -- | Throw an 'IOError' corresponding to the current value of 'getErrno'
331 -- if the result value of the 'IO' action meets the given predicate.
333 throwErrnoIf :: (a -> Bool) -- ^ predicate to apply to the result value
334 -- of the 'IO' operation
335 -> String -- ^ textual description of the location
336 -> IO a -- ^ the 'IO' operation to be executed
338 throwErrnoIf pred loc f =
341 if pred res then throwErrno loc else return res
343 -- | as 'throwErrnoIf', but discards the result of the 'IO' action after
346 throwErrnoIf_ :: (a -> Bool) -> String -> IO a -> IO ()
347 throwErrnoIf_ pred loc f = void $ throwErrnoIf pred loc f
349 -- | as 'throwErrnoIf', but retry the 'IO' action when it yields the
350 -- error code 'eINTR' - this amounts to the standard retry loop for
351 -- interrupted POSIX system calls.
353 throwErrnoIfRetry :: (a -> Bool) -> String -> IO a -> IO a
354 throwErrnoIfRetry pred loc f =
361 then throwErrnoIfRetry pred loc f
365 -- | as 'throwErrnoIfRetry', but checks for operations that would block and
366 -- executes an alternative action before retrying in that case.
368 throwErrnoIfRetryMayBlock
369 :: (a -> Bool) -- ^ predicate to apply to the result value
370 -- of the 'IO' operation
371 -> String -- ^ textual description of the location
372 -> IO a -- ^ the 'IO' operation to be executed
373 -> IO b -- ^ action to execute before retrying if
374 -- an immediate retry would block
376 throwErrnoIfRetryMayBlock pred loc f on_block =
383 then throwErrnoIfRetryMayBlock pred loc f on_block
384 else if err == eWOULDBLOCK || err == eAGAIN
385 then do on_block; throwErrnoIfRetryMayBlock pred loc f on_block
389 -- | as 'throwErrnoIfRetry', but discards the result.
391 throwErrnoIfRetry_ :: (a -> Bool) -> String -> IO a -> IO ()
392 throwErrnoIfRetry_ pred loc f = void $ throwErrnoIfRetry pred loc f
394 -- | as 'throwErrnoIfRetryMayBlock', but discards the result.
396 throwErrnoIfRetryMayBlock_ :: (a -> Bool) -> String -> IO a -> IO b -> IO ()
397 throwErrnoIfRetryMayBlock_ pred loc f on_block
398 = void $ throwErrnoIfRetryMayBlock pred loc f on_block
400 -- | Throw an 'IOError' corresponding to the current value of 'getErrno'
401 -- if the 'IO' action returns a result of @-1@.
403 throwErrnoIfMinus1 :: Num a => String -> IO a -> IO a
404 throwErrnoIfMinus1 = throwErrnoIf (== -1)
406 -- | as 'throwErrnoIfMinus1', but discards the result.
408 throwErrnoIfMinus1_ :: Num a => String -> IO a -> IO ()
409 throwErrnoIfMinus1_ = throwErrnoIf_ (== -1)
411 -- | Throw an 'IOError' corresponding to the current value of 'getErrno'
412 -- if the 'IO' action returns a result of @-1@, but retries in case of
413 -- an interrupted operation.
415 throwErrnoIfMinus1Retry :: Num a => String -> IO a -> IO a
416 throwErrnoIfMinus1Retry = throwErrnoIfRetry (== -1)
418 -- | as 'throwErrnoIfMinus1', but discards the result.
420 throwErrnoIfMinus1Retry_ :: Num a => String -> IO a -> IO ()
421 throwErrnoIfMinus1Retry_ = throwErrnoIfRetry_ (== -1)
423 -- | as 'throwErrnoIfMinus1Retry', but checks for operations that would block.
425 throwErrnoIfMinus1RetryMayBlock :: Num a => String -> IO a -> IO b -> IO a
426 throwErrnoIfMinus1RetryMayBlock = throwErrnoIfRetryMayBlock (== -1)
428 -- | as 'throwErrnoIfMinus1RetryMayBlock', but discards the result.
430 throwErrnoIfMinus1RetryMayBlock_ :: Num a => String -> IO a -> IO b -> IO ()
431 throwErrnoIfMinus1RetryMayBlock_ = throwErrnoIfRetryMayBlock_ (== -1)
433 -- | Throw an 'IOError' corresponding to the current value of 'getErrno'
434 -- if the 'IO' action returns 'nullPtr'.
436 throwErrnoIfNull :: String -> IO (Ptr a) -> IO (Ptr a)
437 throwErrnoIfNull = throwErrnoIf (== nullPtr)
439 -- | Throw an 'IOError' corresponding to the current value of 'getErrno'
440 -- if the 'IO' action returns 'nullPtr',
441 -- but retry in case of an interrupted operation.
443 throwErrnoIfNullRetry :: String -> IO (Ptr a) -> IO (Ptr a)
444 throwErrnoIfNullRetry = throwErrnoIfRetry (== nullPtr)
446 -- | as 'throwErrnoIfNullRetry', but checks for operations that would block.
448 throwErrnoIfNullRetryMayBlock :: String -> IO (Ptr a) -> IO b -> IO (Ptr a)
449 throwErrnoIfNullRetryMayBlock = throwErrnoIfRetryMayBlock (== nullPtr)
451 -- conversion of an "errno" value into IO error
452 -- --------------------------------------------
454 -- | Construct a Haskell 98 I\/O error based on the given 'Errno' value.
455 -- The optional information can be used to improve the accuracy of
458 errnoToIOError :: String -- ^ the location where the error occurred
459 -> Errno -- ^ the error number
460 -> Maybe Handle -- ^ optional handle associated with the error
461 -> Maybe String -- ^ optional filename associated with the error
463 errnoToIOError loc errno maybeHdl maybeName = unsafePerformIO $ do
464 str <- strerror errno >>= peekCString
465 #if __GLASGOW_HASKELL__
466 return (IOError maybeHdl errType loc str maybeName)
469 | errno == eOK = OtherError
470 | errno == e2BIG = ResourceExhausted
471 | errno == eACCES = PermissionDenied
472 | errno == eADDRINUSE = ResourceBusy
473 | errno == eADDRNOTAVAIL = UnsupportedOperation
474 | errno == eADV = OtherError
475 | errno == eAFNOSUPPORT = UnsupportedOperation
476 | errno == eAGAIN = ResourceExhausted
477 | errno == eALREADY = AlreadyExists
478 | errno == eBADF = InvalidArgument
479 | errno == eBADMSG = InappropriateType
480 | errno == eBADRPC = OtherError
481 | errno == eBUSY = ResourceBusy
482 | errno == eCHILD = NoSuchThing
483 | errno == eCOMM = ResourceVanished
484 | errno == eCONNABORTED = OtherError
485 | errno == eCONNREFUSED = NoSuchThing
486 | errno == eCONNRESET = ResourceVanished
487 | errno == eDEADLK = ResourceBusy
488 | errno == eDESTADDRREQ = InvalidArgument
489 | errno == eDIRTY = UnsatisfiedConstraints
490 | errno == eDOM = InvalidArgument
491 | errno == eDQUOT = PermissionDenied
492 | errno == eEXIST = AlreadyExists
493 | errno == eFAULT = OtherError
494 | errno == eFBIG = PermissionDenied
495 | errno == eFTYPE = InappropriateType
496 | errno == eHOSTDOWN = NoSuchThing
497 | errno == eHOSTUNREACH = NoSuchThing
498 | errno == eIDRM = ResourceVanished
499 | errno == eILSEQ = InvalidArgument
500 | errno == eINPROGRESS = AlreadyExists
501 | errno == eINTR = Interrupted
502 | errno == eINVAL = InvalidArgument
503 | errno == eIO = HardwareFault
504 | errno == eISCONN = AlreadyExists
505 | errno == eISDIR = InappropriateType
506 | errno == eLOOP = InvalidArgument
507 | errno == eMFILE = ResourceExhausted
508 | errno == eMLINK = ResourceExhausted
509 | errno == eMSGSIZE = ResourceExhausted
510 | errno == eMULTIHOP = UnsupportedOperation
511 | errno == eNAMETOOLONG = InvalidArgument
512 | errno == eNETDOWN = ResourceVanished
513 | errno == eNETRESET = ResourceVanished
514 | errno == eNETUNREACH = NoSuchThing
515 | errno == eNFILE = ResourceExhausted
516 | errno == eNOBUFS = ResourceExhausted
517 | errno == eNODATA = NoSuchThing
518 | errno == eNODEV = UnsupportedOperation
519 | errno == eNOENT = NoSuchThing
520 | errno == eNOEXEC = InvalidArgument
521 | errno == eNOLCK = ResourceExhausted
522 | errno == eNOLINK = ResourceVanished
523 | errno == eNOMEM = ResourceExhausted
524 | errno == eNOMSG = NoSuchThing
525 | errno == eNONET = NoSuchThing
526 | errno == eNOPROTOOPT = UnsupportedOperation
527 | errno == eNOSPC = ResourceExhausted
528 | errno == eNOSR = ResourceExhausted
529 | errno == eNOSTR = InvalidArgument
530 | errno == eNOSYS = UnsupportedOperation
531 | errno == eNOTBLK = InvalidArgument
532 | errno == eNOTCONN = InvalidArgument
533 | errno == eNOTDIR = InappropriateType
534 | errno == eNOTEMPTY = UnsatisfiedConstraints
535 | errno == eNOTSOCK = InvalidArgument
536 | errno == eNOTTY = IllegalOperation
537 | errno == eNXIO = NoSuchThing
538 | errno == eOPNOTSUPP = UnsupportedOperation
539 | errno == ePERM = PermissionDenied
540 | errno == ePFNOSUPPORT = UnsupportedOperation
541 | errno == ePIPE = ResourceVanished
542 | errno == ePROCLIM = PermissionDenied
543 | errno == ePROCUNAVAIL = UnsupportedOperation
544 | errno == ePROGMISMATCH = ProtocolError
545 | errno == ePROGUNAVAIL = UnsupportedOperation
546 | errno == ePROTO = ProtocolError
547 | errno == ePROTONOSUPPORT = ProtocolError
548 | errno == ePROTOTYPE = ProtocolError
549 | errno == eRANGE = UnsupportedOperation
550 | errno == eREMCHG = ResourceVanished
551 | errno == eREMOTE = IllegalOperation
552 | errno == eROFS = PermissionDenied
553 | errno == eRPCMISMATCH = ProtocolError
554 | errno == eRREMOTE = IllegalOperation
555 | errno == eSHUTDOWN = IllegalOperation
556 | errno == eSOCKTNOSUPPORT = UnsupportedOperation
557 | errno == eSPIPE = UnsupportedOperation
558 | errno == eSRCH = NoSuchThing
559 | errno == eSRMNT = UnsatisfiedConstraints
560 | errno == eSTALE = ResourceVanished
561 | errno == eTIME = TimeExpired
562 | errno == eTIMEDOUT = TimeExpired
563 | errno == eTOOMANYREFS = ResourceExhausted
564 | errno == eTXTBSY = ResourceBusy
565 | errno == eUSERS = ResourceExhausted
566 | errno == eWOULDBLOCK = OtherError
567 | errno == eXDEV = UnsupportedOperation
568 | otherwise = OtherError
570 return (userError (loc ++ ": " ++ str ++ maybe "" (": "++) maybeName))
573 foreign import ccall unsafe "string.h" strerror :: Errno -> IO (Ptr CChar)