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