{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude #-}
module Foreign.C.Error (
Errno(..),
eOK, e2BIG, eACCES, eADDRINUSE, eADDRNOTAVAIL, eADV, eAFNOSUPPORT, eAGAIN,
eALREADY, eBADF, eBADMSG, eBADRPC, eBUSY, eCHILD, eCOMM, eCONNABORTED,
eCONNREFUSED, eCONNRESET, eDEADLK, eDESTADDRREQ, eDIRTY, eDOM, eDQUOT,
eEXIST, eFAULT, eFBIG, eFTYPE, eHOSTDOWN, eHOSTUNREACH, eIDRM, eILSEQ,
eINPROGRESS, eINTR, eINVAL, eIO, eISCONN, eISDIR, eLOOP, eMFILE, eMLINK,
eMSGSIZE, eMULTIHOP, eNAMETOOLONG, eNETDOWN, eNETRESET, eNETUNREACH,
eNFILE, eNOBUFS, eNODATA, eNODEV, eNOENT, eNOEXEC, eNOLCK, eNOLINK,
eNOMEM, eNOMSG, eNONET, eNOPROTOOPT, eNOSPC, eNOSR, eNOSTR, eNOSYS,
eNOTBLK, eNOTCONN, eNOTDIR, eNOTEMPTY, eNOTSOCK, eNOTSUP, eNOTTY, eNXIO,
eOPNOTSUPP, ePERM, ePFNOSUPPORT, ePIPE, ePROCLIM, ePROCUNAVAIL,
ePROGMISMATCH, ePROGUNAVAIL, ePROTO, ePROTONOSUPPORT, ePROTOTYPE,
eRANGE, eREMCHG, eREMOTE, eROFS, eRPCMISMATCH, eRREMOTE, eSHUTDOWN,
eSOCKTNOSUPPORT, eSPIPE, eSRCH, eSRMNT, eSTALE, eTIME, eTIMEDOUT,
eTOOMANYREFS, eTXTBSY, eUSERS, eWOULDBLOCK, eXDEV,
isValidErrno,
getErrno,
resetErrno,
errnoToIOError,
throwErrno,
throwErrnoIf,
throwErrnoIf_,
throwErrnoIfRetry,
throwErrnoIfRetry_,
throwErrnoIfMinus1,
throwErrnoIfMinus1_,
throwErrnoIfMinus1Retry,
throwErrnoIfMinus1Retry_,
throwErrnoIfNull,
throwErrnoIfNullRetry,
throwErrnoIfRetryMayBlock,
throwErrnoIfRetryMayBlock_,
throwErrnoIfMinus1RetryMayBlock,
throwErrnoIfMinus1RetryMayBlock_,
throwErrnoIfNullRetryMayBlock,
throwErrnoPath,
throwErrnoPathIf,
throwErrnoPathIf_,
throwErrnoPathIfNull,
throwErrnoPathIfMinus1,
throwErrnoPathIfMinus1_,
) where
#include "HsBaseConfig.h"
import Foreign.Ptr
import Foreign.C.Types
import Foreign.C.String
import Data.Functor ( void )
import Data.Maybe
import GHC.IO
import GHC.IO.Exception
import GHC.IO.Handle.Types
import GHC.Num
import GHC.Base
newtype Errno = Errno CInt
instance Eq Errno where
errno1 :: Errno
errno1@(Errno no1 :: CInt
no1) == :: Errno -> Errno -> Bool
== errno2 :: Errno
errno2@(Errno no2 :: CInt
no2)
| Errno -> Bool
isValidErrno Errno
errno1 Bool -> Bool -> Bool
&& Errno -> Bool
isValidErrno Errno
errno2 = CInt
no1 CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
no2
| Bool
otherwise = Bool
False
eOK, e2BIG, eACCES, eADDRINUSE, eADDRNOTAVAIL, eADV, eAFNOSUPPORT, eAGAIN,
eALREADY, eBADF, eBADMSG, eBADRPC, eBUSY, eCHILD, eCOMM, eCONNABORTED,
eCONNREFUSED, eCONNRESET, eDEADLK, eDESTADDRREQ, eDIRTY, eDOM, eDQUOT,
eEXIST, eFAULT, eFBIG, eFTYPE, eHOSTDOWN, eHOSTUNREACH, eIDRM, eILSEQ,
eINPROGRESS, eINTR, eINVAL, eIO, eISCONN, eISDIR, eLOOP, eMFILE, eMLINK,
eMSGSIZE, eMULTIHOP, eNAMETOOLONG, eNETDOWN, eNETRESET, eNETUNREACH,
eNFILE, eNOBUFS, eNODATA, eNODEV, eNOENT, eNOEXEC, eNOLCK, eNOLINK,
eNOMEM, eNOMSG, eNONET, eNOPROTOOPT, eNOSPC, eNOSR, eNOSTR, eNOSYS,
eNOTBLK, eNOTCONN, eNOTDIR, eNOTEMPTY, eNOTSOCK, eNOTSUP, eNOTTY, eNXIO,
eOPNOTSUPP, ePERM, ePFNOSUPPORT, ePIPE, ePROCLIM, ePROCUNAVAIL,
ePROGMISMATCH, ePROGUNAVAIL, ePROTO, ePROTONOSUPPORT, ePROTOTYPE,
eRANGE, eREMCHG, eREMOTE, eROFS, eRPCMISMATCH, eRREMOTE, eSHUTDOWN,
eSOCKTNOSUPPORT, eSPIPE, eSRCH, eSRMNT, eSTALE, eTIME, eTIMEDOUT,
eTOOMANYREFS, eTXTBSY, eUSERS, eWOULDBLOCK, eXDEV :: Errno
eOK :: Errno
eOK = CInt -> Errno
Errno 0
e2BIG :: Errno
e2BIG = CInt -> Errno
Errno (CONST_E2BIG)
eACCES :: Errno
eACCES = CInt -> Errno
Errno (CONST_EACCES)
eADDRINUSE :: Errno
eADDRINUSE = CInt -> Errno
Errno (CONST_EADDRINUSE)
eADDRNOTAVAIL :: Errno
eADDRNOTAVAIL = CInt -> Errno
Errno (CONST_EADDRNOTAVAIL)
eADV :: Errno
eADV = CInt -> Errno
Errno (CONST_EADV)
eAFNOSUPPORT :: Errno
eAFNOSUPPORT = CInt -> Errno
Errno (CONST_EAFNOSUPPORT)
eAGAIN :: Errno
eAGAIN = CInt -> Errno
Errno (CONST_EAGAIN)
eALREADY :: Errno
eALREADY = CInt -> Errno
Errno (CONST_EALREADY)
eBADF :: Errno
eBADF = CInt -> Errno
Errno (CONST_EBADF)
eBADMSG :: Errno
eBADMSG = CInt -> Errno
Errno (CONST_EBADMSG)
eBADRPC :: Errno
eBADRPC = CInt -> Errno
Errno (CONST_EBADRPC)
eBUSY :: Errno
eBUSY = CInt -> Errno
Errno (CONST_EBUSY)
eCHILD :: Errno
eCHILD = CInt -> Errno
Errno (CONST_ECHILD)
eCOMM :: Errno
eCOMM = CInt -> Errno
Errno (CONST_ECOMM)
eCONNABORTED :: Errno
eCONNABORTED = CInt -> Errno
Errno (CONST_ECONNABORTED)
eCONNREFUSED :: Errno
eCONNREFUSED = CInt -> Errno
Errno (CONST_ECONNREFUSED)
eCONNRESET :: Errno
eCONNRESET = CInt -> Errno
Errno (CONST_ECONNRESET)
eDEADLK :: Errno
eDEADLK = CInt -> Errno
Errno (CONST_EDEADLK)
eDESTADDRREQ :: Errno
eDESTADDRREQ = CInt -> Errno
Errno (CONST_EDESTADDRREQ)
eDIRTY :: Errno
eDIRTY = CInt -> Errno
Errno (CONST_EDIRTY)
eDOM :: Errno
eDOM = CInt -> Errno
Errno (CONST_EDOM)
eDQUOT :: Errno
eDQUOT = CInt -> Errno
Errno (CONST_EDQUOT)
eEXIST :: Errno
eEXIST = CInt -> Errno
Errno (CONST_EEXIST)
eFAULT :: Errno
eFAULT = CInt -> Errno
Errno (CONST_EFAULT)
eFBIG :: Errno
eFBIG = CInt -> Errno
Errno (CONST_EFBIG)
eFTYPE :: Errno
eFTYPE = CInt -> Errno
Errno (CONST_EFTYPE)
eHOSTDOWN :: Errno
eHOSTDOWN = CInt -> Errno
Errno (CONST_EHOSTDOWN)
eHOSTUNREACH :: Errno
eHOSTUNREACH = CInt -> Errno
Errno (CONST_EHOSTUNREACH)
eIDRM :: Errno
eIDRM = CInt -> Errno
Errno (CONST_EIDRM)
eILSEQ :: Errno
eILSEQ = CInt -> Errno
Errno (CONST_EILSEQ)
eINPROGRESS :: Errno
eINPROGRESS = CInt -> Errno
Errno (CONST_EINPROGRESS)
eINTR :: Errno
eINTR = CInt -> Errno
Errno (CONST_EINTR)
eINVAL :: Errno
eINVAL = CInt -> Errno
Errno (CONST_EINVAL)
eIO :: Errno
eIO = CInt -> Errno
Errno (CONST_EIO)
eISCONN :: Errno
eISCONN = CInt -> Errno
Errno (CONST_EISCONN)
eISDIR :: Errno
eISDIR = CInt -> Errno
Errno (CONST_EISDIR)
eLOOP :: Errno
eLOOP = CInt -> Errno
Errno (CONST_ELOOP)
eMFILE :: Errno
eMFILE = CInt -> Errno
Errno (CONST_EMFILE)
eMLINK :: Errno
eMLINK = CInt -> Errno
Errno (CONST_EMLINK)
eMSGSIZE :: Errno
eMSGSIZE = CInt -> Errno
Errno (CONST_EMSGSIZE)
eMULTIHOP :: Errno
eMULTIHOP = CInt -> Errno
Errno (CONST_EMULTIHOP)
eNAMETOOLONG :: Errno
eNAMETOOLONG = CInt -> Errno
Errno (CONST_ENAMETOOLONG)
eNETDOWN :: Errno
eNETDOWN = CInt -> Errno
Errno (CONST_ENETDOWN)
eNETRESET :: Errno
eNETRESET = CInt -> Errno
Errno (CONST_ENETRESET)
eNETUNREACH :: Errno
eNETUNREACH = CInt -> Errno
Errno (CONST_ENETUNREACH)
eNFILE :: Errno
eNFILE = CInt -> Errno
Errno (CONST_ENFILE)
eNOBUFS :: Errno
eNOBUFS = CInt -> Errno
Errno (CONST_ENOBUFS)
eNODATA :: Errno
eNODATA = CInt -> Errno
Errno (CONST_ENODATA)
eNODEV :: Errno
eNODEV = CInt -> Errno
Errno (CONST_ENODEV)
eNOENT :: Errno
eNOENT = CInt -> Errno
Errno (CONST_ENOENT)
eNOEXEC :: Errno
eNOEXEC = CInt -> Errno
Errno (CONST_ENOEXEC)
eNOLCK :: Errno
eNOLCK = CInt -> Errno
Errno (CONST_ENOLCK)
eNOLINK :: Errno
eNOLINK = CInt -> Errno
Errno (CONST_ENOLINK)
eNOMEM :: Errno
eNOMEM = CInt -> Errno
Errno (CONST_ENOMEM)
eNOMSG :: Errno
eNOMSG = CInt -> Errno
Errno (CONST_ENOMSG)
eNONET :: Errno
eNONET = CInt -> Errno
Errno (CONST_ENONET)
eNOPROTOOPT :: Errno
eNOPROTOOPT = CInt -> Errno
Errno (CONST_ENOPROTOOPT)
eNOSPC :: Errno
eNOSPC = CInt -> Errno
Errno (CONST_ENOSPC)
eNOSR :: Errno
eNOSR = CInt -> Errno
Errno (CONST_ENOSR)
eNOSTR :: Errno
eNOSTR = CInt -> Errno
Errno (CONST_ENOSTR)
eNOSYS :: Errno
eNOSYS = CInt -> Errno
Errno (CONST_ENOSYS)
eNOTBLK :: Errno
eNOTBLK = CInt -> Errno
Errno (CONST_ENOTBLK)
eNOTCONN :: Errno
eNOTCONN = CInt -> Errno
Errno (CONST_ENOTCONN)
eNOTDIR :: Errno
eNOTDIR = CInt -> Errno
Errno (CONST_ENOTDIR)
eNOTEMPTY :: Errno
eNOTEMPTY = CInt -> Errno
Errno (CONST_ENOTEMPTY)
eNOTSOCK :: Errno
eNOTSOCK = CInt -> Errno
Errno (CONST_ENOTSOCK)
eNOTSUP :: Errno
eNOTSUP = CInt -> Errno
Errno (CONST_ENOTSUP)
eNOTTY :: Errno
eNOTTY = CInt -> Errno
Errno (CONST_ENOTTY)
eNXIO :: Errno
eNXIO = CInt -> Errno
Errno (CONST_ENXIO)
eOPNOTSUPP :: Errno
eOPNOTSUPP = CInt -> Errno
Errno (CONST_EOPNOTSUPP)
ePERM :: Errno
ePERM = CInt -> Errno
Errno (CONST_EPERM)
ePFNOSUPPORT :: Errno
ePFNOSUPPORT = CInt -> Errno
Errno (CONST_EPFNOSUPPORT)
ePIPE :: Errno
ePIPE = CInt -> Errno
Errno (CONST_EPIPE)
ePROCLIM :: Errno
ePROCLIM = CInt -> Errno
Errno (CONST_EPROCLIM)
ePROCUNAVAIL :: Errno
ePROCUNAVAIL = CInt -> Errno
Errno (CONST_EPROCUNAVAIL)
ePROGMISMATCH :: Errno
ePROGMISMATCH = CInt -> Errno
Errno (CONST_EPROGMISMATCH)
ePROGUNAVAIL :: Errno
ePROGUNAVAIL = CInt -> Errno
Errno (CONST_EPROGUNAVAIL)
ePROTO :: Errno
ePROTO = CInt -> Errno
Errno (CONST_EPROTO)
ePROTONOSUPPORT :: Errno
ePROTONOSUPPORT = CInt -> Errno
Errno (CONST_EPROTONOSUPPORT)
ePROTOTYPE :: Errno
ePROTOTYPE = CInt -> Errno
Errno (CONST_EPROTOTYPE)
eRANGE :: Errno
eRANGE = CInt -> Errno
Errno (CONST_ERANGE)
eREMCHG :: Errno
eREMCHG = CInt -> Errno
Errno (CONST_EREMCHG)
eREMOTE :: Errno
eREMOTE = CInt -> Errno
Errno (CONST_EREMOTE)
eROFS :: Errno
eROFS = CInt -> Errno
Errno (CONST_EROFS)
eRPCMISMATCH :: Errno
eRPCMISMATCH = CInt -> Errno
Errno (CONST_ERPCMISMATCH)
eRREMOTE :: Errno
eRREMOTE = CInt -> Errno
Errno (CONST_ERREMOTE)
eSHUTDOWN :: Errno
eSHUTDOWN = CInt -> Errno
Errno (CONST_ESHUTDOWN)
eSOCKTNOSUPPORT :: Errno
eSOCKTNOSUPPORT = CInt -> Errno
Errno (CONST_ESOCKTNOSUPPORT)
eSPIPE :: Errno
eSPIPE = CInt -> Errno
Errno (CONST_ESPIPE)
eSRCH :: Errno
eSRCH = CInt -> Errno
Errno (CONST_ESRCH)
eSRMNT :: Errno
eSRMNT = CInt -> Errno
Errno (CONST_ESRMNT)
eSTALE :: Errno
eSTALE = CInt -> Errno
Errno (CONST_ESTALE)
eTIME :: Errno
eTIME = CInt -> Errno
Errno (CONST_ETIME)
eTIMEDOUT :: Errno
eTIMEDOUT = CInt -> Errno
Errno (CONST_ETIMEDOUT)
eTOOMANYREFS :: Errno
eTOOMANYREFS = CInt -> Errno
Errno (CONST_ETOOMANYREFS)
eTXTBSY :: Errno
eTXTBSY = CInt -> Errno
Errno (CONST_ETXTBSY)
eUSERS :: Errno
eUSERS = CInt -> Errno
Errno (CONST_EUSERS)
eWOULDBLOCK :: Errno
eWOULDBLOCK = CInt -> Errno
Errno (CONST_EWOULDBLOCK)
eXDEV :: Errno
eXDEV = CInt -> Errno
Errno (CONST_EXDEV)
isValidErrno :: Errno -> Bool
isValidErrno :: Errno -> Bool
isValidErrno (Errno errno :: CInt
errno) = CInt
errno CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= -1
getErrno :: IO Errno
getErrno :: IO Errno
getErrno = do CInt
e <- IO CInt
get_errno; Errno -> IO Errno
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt -> Errno
Errno CInt
e)
foreign import ccall unsafe "HsBase.h __hscore_get_errno" get_errno :: IO CInt
resetErrno :: IO ()
resetErrno :: IO ()
resetErrno = CInt -> IO ()
set_errno 0
foreign import ccall unsafe "HsBase.h __hscore_set_errno" set_errno :: CInt -> IO ()
throwErrno :: String
-> IO a
throwErrno :: String -> IO a
throwErrno loc :: String
loc =
do
Errno
errno <- IO Errno
getErrno
IOError -> IO a
forall a. IOError -> IO a
ioError (String -> Errno -> Maybe Handle -> Maybe String -> IOError
errnoToIOError String
loc Errno
errno Maybe Handle
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing)
throwErrnoIf :: (a -> Bool)
-> String
-> IO a
-> IO a
throwErrnoIf :: (a -> Bool) -> String -> IO a -> IO a
throwErrnoIf pred :: a -> Bool
pred loc :: String
loc f :: IO a
f =
do
a
res <- IO a
f
if a -> Bool
pred a
res then String -> IO a
forall a. String -> IO a
throwErrno String
loc else a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
res
throwErrnoIf_ :: (a -> Bool) -> String -> IO a -> IO ()
throwErrnoIf_ :: (a -> Bool) -> String -> IO a -> IO ()
throwErrnoIf_ pred :: a -> Bool
pred loc :: String
loc f :: IO a
f = IO a -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO a -> IO ()) -> IO a -> IO ()
forall a b. (a -> b) -> a -> b
$ (a -> Bool) -> String -> IO a -> IO a
forall a. (a -> Bool) -> String -> IO a -> IO a
throwErrnoIf a -> Bool
pred String
loc IO a
f
throwErrnoIfRetry :: (a -> Bool) -> String -> IO a -> IO a
throwErrnoIfRetry :: (a -> Bool) -> String -> IO a -> IO a
throwErrnoIfRetry pred :: a -> Bool
pred loc :: String
loc f :: IO a
f =
do
a
res <- IO a
f
if a -> Bool
pred a
res
then do
Errno
err <- IO Errno
getErrno
if Errno
err Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eINTR
then (a -> Bool) -> String -> IO a -> IO a
forall a. (a -> Bool) -> String -> IO a -> IO a
throwErrnoIfRetry a -> Bool
pred String
loc IO a
f
else String -> IO a
forall a. String -> IO a
throwErrno String
loc
else a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
res
throwErrnoIfRetryMayBlock
:: (a -> Bool)
-> String
-> IO a
-> IO b
-> IO a
throwErrnoIfRetryMayBlock :: (a -> Bool) -> String -> IO a -> IO b -> IO a
throwErrnoIfRetryMayBlock pred :: a -> Bool
pred loc :: String
loc f :: IO a
f on_block :: IO b
on_block =
do
a
res <- IO a
f
if a -> Bool
pred a
res
then do
Errno
err <- IO Errno
getErrno
if Errno
err Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eINTR
then (a -> Bool) -> String -> IO a -> IO b -> IO a
forall a b. (a -> Bool) -> String -> IO a -> IO b -> IO a
throwErrnoIfRetryMayBlock a -> Bool
pred String
loc IO a
f IO b
on_block
else if Errno
err Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eWOULDBLOCK Bool -> Bool -> Bool
|| Errno
err Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eAGAIN
then do b
_ <- IO b
on_block
(a -> Bool) -> String -> IO a -> IO b -> IO a
forall a b. (a -> Bool) -> String -> IO a -> IO b -> IO a
throwErrnoIfRetryMayBlock a -> Bool
pred String
loc IO a
f IO b
on_block
else String -> IO a
forall a. String -> IO a
throwErrno String
loc
else a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
res
throwErrnoIfRetry_ :: (a -> Bool) -> String -> IO a -> IO ()
throwErrnoIfRetry_ :: (a -> Bool) -> String -> IO a -> IO ()
throwErrnoIfRetry_ pred :: a -> Bool
pred loc :: String
loc f :: IO a
f = IO a -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO a -> IO ()) -> IO a -> IO ()
forall a b. (a -> b) -> a -> b
$ (a -> Bool) -> String -> IO a -> IO a
forall a. (a -> Bool) -> String -> IO a -> IO a
throwErrnoIfRetry a -> Bool
pred String
loc IO a
f
throwErrnoIfRetryMayBlock_ :: (a -> Bool) -> String -> IO a -> IO b -> IO ()
throwErrnoIfRetryMayBlock_ :: (a -> Bool) -> String -> IO a -> IO b -> IO ()
throwErrnoIfRetryMayBlock_ pred :: a -> Bool
pred loc :: String
loc f :: IO a
f on_block :: IO b
on_block
= IO a -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO a -> IO ()) -> IO a -> IO ()
forall a b. (a -> b) -> a -> b
$ (a -> Bool) -> String -> IO a -> IO b -> IO a
forall a b. (a -> Bool) -> String -> IO a -> IO b -> IO a
throwErrnoIfRetryMayBlock a -> Bool
pred String
loc IO a
f IO b
on_block
throwErrnoIfMinus1 :: (Eq a, Num a) => String -> IO a -> IO a
throwErrnoIfMinus1 :: String -> IO a -> IO a
throwErrnoIfMinus1 = (a -> Bool) -> String -> IO a -> IO a
forall a. (a -> Bool) -> String -> IO a -> IO a
throwErrnoIf (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== -1)
throwErrnoIfMinus1_ :: (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ :: String -> IO a -> IO ()
throwErrnoIfMinus1_ = (a -> Bool) -> String -> IO a -> IO ()
forall a. (a -> Bool) -> String -> IO a -> IO ()
throwErrnoIf_ (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== -1)
throwErrnoIfMinus1Retry :: (Eq a, Num a) => String -> IO a -> IO a
throwErrnoIfMinus1Retry :: String -> IO a -> IO a
throwErrnoIfMinus1Retry = (a -> Bool) -> String -> IO a -> IO a
forall a. (a -> Bool) -> String -> IO a -> IO a
throwErrnoIfRetry (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== -1)
throwErrnoIfMinus1Retry_ :: (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1Retry_ :: String -> IO a -> IO ()
throwErrnoIfMinus1Retry_ = (a -> Bool) -> String -> IO a -> IO ()
forall a. (a -> Bool) -> String -> IO a -> IO ()
throwErrnoIfRetry_ (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== -1)
throwErrnoIfMinus1RetryMayBlock :: (Eq a, Num a)
=> String -> IO a -> IO b -> IO a
throwErrnoIfMinus1RetryMayBlock :: String -> IO a -> IO b -> IO a
throwErrnoIfMinus1RetryMayBlock = (a -> Bool) -> String -> IO a -> IO b -> IO a
forall a b. (a -> Bool) -> String -> IO a -> IO b -> IO a
throwErrnoIfRetryMayBlock (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== -1)
throwErrnoIfMinus1RetryMayBlock_ :: (Eq a, Num a)
=> String -> IO a -> IO b -> IO ()
throwErrnoIfMinus1RetryMayBlock_ :: String -> IO a -> IO b -> IO ()
throwErrnoIfMinus1RetryMayBlock_ = (a -> Bool) -> String -> IO a -> IO b -> IO ()
forall a b. (a -> Bool) -> String -> IO a -> IO b -> IO ()
throwErrnoIfRetryMayBlock_ (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== -1)
throwErrnoIfNull :: String -> IO (Ptr a) -> IO (Ptr a)
throwErrnoIfNull :: String -> IO (Ptr a) -> IO (Ptr a)
throwErrnoIfNull = (Ptr a -> Bool) -> String -> IO (Ptr a) -> IO (Ptr a)
forall a. (a -> Bool) -> String -> IO a -> IO a
throwErrnoIf (Ptr a -> Ptr a -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr a
forall a. Ptr a
nullPtr)
throwErrnoIfNullRetry :: String -> IO (Ptr a) -> IO (Ptr a)
throwErrnoIfNullRetry :: String -> IO (Ptr a) -> IO (Ptr a)
throwErrnoIfNullRetry = (Ptr a -> Bool) -> String -> IO (Ptr a) -> IO (Ptr a)
forall a. (a -> Bool) -> String -> IO a -> IO a
throwErrnoIfRetry (Ptr a -> Ptr a -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr a
forall a. Ptr a
nullPtr)
throwErrnoIfNullRetryMayBlock :: String -> IO (Ptr a) -> IO b -> IO (Ptr a)
throwErrnoIfNullRetryMayBlock :: String -> IO (Ptr a) -> IO b -> IO (Ptr a)
throwErrnoIfNullRetryMayBlock = (Ptr a -> Bool) -> String -> IO (Ptr a) -> IO b -> IO (Ptr a)
forall a b. (a -> Bool) -> String -> IO a -> IO b -> IO a
throwErrnoIfRetryMayBlock (Ptr a -> Ptr a -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr a
forall a. Ptr a
nullPtr)
throwErrnoPath :: String -> FilePath -> IO a
throwErrnoPath :: String -> String -> IO a
throwErrnoPath loc :: String
loc path :: String
path =
do
Errno
errno <- IO Errno
getErrno
IOError -> IO a
forall a. IOError -> IO a
ioError (String -> Errno -> Maybe Handle -> Maybe String -> IOError
errnoToIOError String
loc Errno
errno Maybe Handle
forall a. Maybe a
Nothing (String -> Maybe String
forall a. a -> Maybe a
Just String
path))
throwErrnoPathIf :: (a -> Bool) -> String -> FilePath -> IO a -> IO a
throwErrnoPathIf :: (a -> Bool) -> String -> String -> IO a -> IO a
throwErrnoPathIf pred :: a -> Bool
pred loc :: String
loc path :: String
path f :: IO a
f =
do
a
res <- IO a
f
if a -> Bool
pred a
res then String -> String -> IO a
forall a. String -> String -> IO a
throwErrnoPath String
loc String
path else a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
res
throwErrnoPathIf_ :: (a -> Bool) -> String -> FilePath -> IO a -> IO ()
throwErrnoPathIf_ :: (a -> Bool) -> String -> String -> IO a -> IO ()
throwErrnoPathIf_ pred :: a -> Bool
pred loc :: String
loc path :: String
path f :: IO a
f = IO a -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO a -> IO ()) -> IO a -> IO ()
forall a b. (a -> b) -> a -> b
$ (a -> Bool) -> String -> String -> IO a -> IO a
forall a. (a -> Bool) -> String -> String -> IO a -> IO a
throwErrnoPathIf a -> Bool
pred String
loc String
path IO a
f
throwErrnoPathIfNull :: String -> FilePath -> IO (Ptr a) -> IO (Ptr a)
throwErrnoPathIfNull :: String -> String -> IO (Ptr a) -> IO (Ptr a)
throwErrnoPathIfNull = (Ptr a -> Bool) -> String -> String -> IO (Ptr a) -> IO (Ptr a)
forall a. (a -> Bool) -> String -> String -> IO a -> IO a
throwErrnoPathIf (Ptr a -> Ptr a -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr a
forall a. Ptr a
nullPtr)
throwErrnoPathIfMinus1 :: (Eq a, Num a) => String -> FilePath -> IO a -> IO a
throwErrnoPathIfMinus1 :: String -> String -> IO a -> IO a
throwErrnoPathIfMinus1 = (a -> Bool) -> String -> String -> IO a -> IO a
forall a. (a -> Bool) -> String -> String -> IO a -> IO a
throwErrnoPathIf (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== -1)
throwErrnoPathIfMinus1_ :: (Eq a, Num a) => String -> FilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ :: String -> String -> IO a -> IO ()
throwErrnoPathIfMinus1_ = (a -> Bool) -> String -> String -> IO a -> IO ()
forall a. (a -> Bool) -> String -> String -> IO a -> IO ()
throwErrnoPathIf_ (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== -1)
errnoToIOError :: String
-> Errno
-> Maybe Handle
-> Maybe String
-> IOError
errnoToIOError :: String -> Errno -> Maybe Handle -> Maybe String -> IOError
errnoToIOError loc :: String
loc errno :: Errno
errno maybeHdl :: Maybe Handle
maybeHdl maybeName :: Maybe String
maybeName = IO IOError -> IOError
forall a. IO a -> a
unsafePerformIO (IO IOError -> IOError) -> IO IOError -> IOError
forall a b. (a -> b) -> a -> b
$ do
String
str <- Errno -> IO (Ptr CChar)
strerror Errno
errno IO (Ptr CChar) -> (Ptr CChar -> IO String) -> IO String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr CChar -> IO String
peekCString
IOError -> IO IOError
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOError
IOError Maybe Handle
maybeHdl IOErrorType
errType String
loc String
str (CInt -> Maybe CInt
forall a. a -> Maybe a
Just CInt
errno') Maybe String
maybeName)
where
Errno errno' :: CInt
errno' = Errno
errno
errType :: IOErrorType
errType
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eOK = IOErrorType
OtherError
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
e2BIG = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eACCES = IOErrorType
PermissionDenied
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eADDRINUSE = IOErrorType
ResourceBusy
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eADDRNOTAVAIL = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eADV = IOErrorType
OtherError
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eAFNOSUPPORT = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eAGAIN = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eALREADY = IOErrorType
AlreadyExists
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eBADF = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eBADMSG = IOErrorType
InappropriateType
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eBADRPC = IOErrorType
OtherError
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eBUSY = IOErrorType
ResourceBusy
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eCHILD = IOErrorType
NoSuchThing
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eCOMM = IOErrorType
ResourceVanished
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eCONNABORTED = IOErrorType
OtherError
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eCONNREFUSED = IOErrorType
NoSuchThing
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eCONNRESET = IOErrorType
ResourceVanished
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eDEADLK = IOErrorType
ResourceBusy
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eDESTADDRREQ = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eDIRTY = IOErrorType
UnsatisfiedConstraints
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eDOM = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eDQUOT = IOErrorType
PermissionDenied
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eEXIST = IOErrorType
AlreadyExists
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eFAULT = IOErrorType
OtherError
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eFBIG = IOErrorType
PermissionDenied
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eFTYPE = IOErrorType
InappropriateType
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eHOSTDOWN = IOErrorType
NoSuchThing
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eHOSTUNREACH = IOErrorType
NoSuchThing
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eIDRM = IOErrorType
ResourceVanished
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eILSEQ = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eINPROGRESS = IOErrorType
AlreadyExists
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eINTR = IOErrorType
Interrupted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eINVAL = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eIO = IOErrorType
HardwareFault
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eISCONN = IOErrorType
AlreadyExists
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eISDIR = IOErrorType
InappropriateType
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eLOOP = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eMFILE = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eMLINK = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eMSGSIZE = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eMULTIHOP = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNAMETOOLONG = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNETDOWN = IOErrorType
ResourceVanished
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNETRESET = IOErrorType
ResourceVanished
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNETUNREACH = IOErrorType
NoSuchThing
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNFILE = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOBUFS = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNODATA = IOErrorType
NoSuchThing
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNODEV = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOENT = IOErrorType
NoSuchThing
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOEXEC = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOLCK = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOLINK = IOErrorType
ResourceVanished
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOMEM = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOMSG = IOErrorType
NoSuchThing
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNONET = IOErrorType
NoSuchThing
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOPROTOOPT = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOSPC = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOSR = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOSTR = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOSYS = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOTBLK = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOTCONN = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOTDIR = IOErrorType
InappropriateType
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOTEMPTY = IOErrorType
UnsatisfiedConstraints
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOTSOCK = IOErrorType
InvalidArgument
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNOTTY = IOErrorType
IllegalOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eNXIO = IOErrorType
NoSuchThing
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eOPNOTSUPP = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePERM = IOErrorType
PermissionDenied
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePFNOSUPPORT = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePIPE = IOErrorType
ResourceVanished
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePROCLIM = IOErrorType
PermissionDenied
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePROCUNAVAIL = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePROGMISMATCH = IOErrorType
ProtocolError
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePROGUNAVAIL = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePROTO = IOErrorType
ProtocolError
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePROTONOSUPPORT = IOErrorType
ProtocolError
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePROTOTYPE = IOErrorType
ProtocolError
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eRANGE = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eREMCHG = IOErrorType
ResourceVanished
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eREMOTE = IOErrorType
IllegalOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eROFS = IOErrorType
PermissionDenied
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eRPCMISMATCH = IOErrorType
ProtocolError
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eRREMOTE = IOErrorType
IllegalOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eSHUTDOWN = IOErrorType
IllegalOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eSOCKTNOSUPPORT = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eSPIPE = IOErrorType
UnsupportedOperation
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eSRCH = IOErrorType
NoSuchThing
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eSRMNT = IOErrorType
UnsatisfiedConstraints
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eSTALE = IOErrorType
ResourceVanished
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eTIME = IOErrorType
TimeExpired
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eTIMEDOUT = IOErrorType
TimeExpired
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eTOOMANYREFS = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eTXTBSY = IOErrorType
ResourceBusy
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eUSERS = IOErrorType
ResourceExhausted
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eWOULDBLOCK = IOErrorType
OtherError
| Errno
errno Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eXDEV = IOErrorType
UnsupportedOperation
| Bool
otherwise = IOErrorType
OtherError
foreign import ccall unsafe "string.h" strerror :: Errno -> IO (Ptr CChar)