libfuse3-0.2.0.1: A Haskell binding for libfuse-3.x
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.LibFuse3.Utils

Description

Miscellaneous utilities provided for convenience.

These can be used for general purpose and are not directly related to FUSE.

Synopsis

Bitsets

testBitSet :: Bits a => a -> a -> Bool Source #

testBitSet bits mask is True iff all bits in mask are set in bits.

testBitSet bits mask ≡ bits .&. mask == mask

Errno

unErrno :: Errno -> CInt Source #

Unwraps the newtype Errno.

ioErrorToErrno :: IOError -> Maybe Errno Source #

Attempts to extract an Errno from an IOError assuming it is constructed with errnoToIOError (typically via throwErrno).

throwErrnoOf Source #

Arguments

:: String

textual description of the error location

-> Errno 
-> IO a 

Like throwErrno but takes an Errno as a parameter instead of reading from getErrno.

This is an inverse of tryErrno:

tryErrno (throwErrnoOf _ e) ≡ pure (Left e)

tryErrno :: IO a -> IO (Either Errno a) Source #

Catches an exception constructed with errnoToIOError and extracts Errno from it.

tryErrno_ :: IO a -> IO Errno Source #

Like tryErrno but discards the result of the original action.

If no exceptions, returns eOK.

tryErrno' :: IO a -> IO (Either Errno a) Source #

Like tryErrno but also catches non-Errno errors to return eIO.

tryErrno_' :: IO a -> IO Errno Source #

Like tryErrno_ but also catches non-Errno errors to return eIO.

File I/O

pread :: Fd -> ByteCount -> FileOffset -> IO ByteString Source #

Reads from a file descriptor at a given offset.

Fewer bytes may be read than requested. On error, throws an IOError corresponding to the errno.

pwrite :: Fd -> ByteString -> FileOffset -> IO CSsize Source #

Writes to a file descriptor at a given offset.

Returns the number of bytes written. Fewer bytes may be written than requested. On error, throws an IOError corresponding to the errno.

c_pread :: CInt -> Ptr a -> CSize -> COff -> IO CSsize Source #

A foreign import of pread(2)

c_pwrite :: CInt -> Ptr a -> CSize -> COff -> IO CSsize Source #

A foreign import of pwrite(2)

Marshalling strings

pokeCStringLen0 :: CStringLen -> String -> IO () Source #

Marshals a Haskell string into a NUL terminated C string in a locale-dependent way.

Does withCStringLen and copies it into the destination buffer.

The Haskell string should not contain NUL characters.

If the destination buffer is not long enough to hold the source string, it is truncated and a NUL byte is inserted at the end of the buffer.

TimeSpec

timeSpecToPOSIXTime :: TimeSpec -> POSIXTime Source #

Converts a TimeSpec to a POSIXTime.

This is the same conversion as the unix package does (as of writing).