Foreign.C.Error (original) (raw)

Haskell representations of errno values

newtype Errno Source #

Haskell representation for errno values. The implementation is deliberately exposed, to allow users to add their own definitions of [Errno](Foreign-C-Error.html#t:Errno "Foreign.C.Error") values.

Instances

Instances details

Common errno symbols

Different operating systems and/or C libraries often support different values of errno. This module defines the common values, but due to the open definition of [Errno](Foreign-C-Error.html#t:Errno "Foreign.C.Error") users may add definitions which are not predefined.

Errno functions

getErrno :: IO Errno Source #

Get the current value of errno in the current thread.

On GHC, the runtime will ensure that any Haskell thread will only see "its own"errno, by saving and restoring the value when Haskell threads are scheduled across OS threads.

Guards for IO operations that may fail

throwErrnoIf Source #

Arguments

:: (a -> Bool) predicate to apply to the result value of the IO operation
-> String textual description of the location
-> IO a the IO operation to be executed
-> IO a

Throw an [IOException](Control-Exception.html#t:IOException "Control.Exception") corresponding to the current value of [getErrno](Foreign-C-Error.html#v:getErrno "Foreign.C.Error") if the result value of the [IO](System-IO.html#t:IO "System.IO") action meets the given predicate.

throwErrnoIfRetryMayBlock Source #

Arguments

:: (a -> Bool) predicate to apply to the result value of the IO operation
-> String textual description of the location
-> IO a the IO operation to be executed
-> IO b action to execute before retrying if an immediate retry would block
-> IO a

as [throwErrnoIfRetry](Foreign-C-Error.html#v:throwErrnoIfRetry "Foreign.C.Error"), but additionally if the operation yields the error code [eAGAIN](Foreign-C-Error.html#v:eAGAIN "Foreign.C.Error") or [eWOULDBLOCK](Foreign-C-Error.html#v:eWOULDBLOCK "Foreign.C.Error"), an alternative action is executed before retrying.