unix-bytestring- Unix/Posix-specific functions for ByteStrings.

Portabilitynon-portable (POSIX.1, XPG4.2; hsc2hs, FFI)
Safe HaskellSafe-Infered




Imports the C struct iovec type and provides conversion between CIovecs and strict ByteStrings.


The struct iovec type

data CIovec Source

Haskell type representing the C struct iovec type. This is exactly like CStringLen except there's actually struct definition on the C side.




iov_base :: !(Ptr Word8)
iov_len :: !CSize


unsafeByteString2CIovec :: ByteString -> CIovecSource

O(1) construction Convert a ByteString into an CIovec.

This function is unsafe in two ways:

  • After calling this function the CIovec shares the underlying byte buffer with the original ByteString. Thus, modifying the CIovec either in C or using poke will cause the contents of the ByteString to change, breaking referential transparency. Other ByteStrings created by sharing (such as those produced via take or drop) will also reflect these changes.
  • Also, even though the CIovec shares the underlying byte buffer, it does so in a way that will not keep the original ByteString alive with respect to garbage collection. Thus, the byte buffer could be collected out from under the CIovec. To prevent this, you must use touchByteString after the last point where the CIovec is needed.

touchByteString :: ByteString -> IO ()Source

Keep the ByteString alive. See unsafeByteString2CIovec.

unsafeUseAsCIovec :: ByteString -> (CIovec -> IO a) -> IO aSource

O(1) construction Use a ByteString with a function requiring a CIovec.

This function does zero copying, and merely unwraps a ByteString to appear as an CIovec. It is unsafe in the same way as unsafeByteString2CIovec.

useAsCIovec :: ByteString -> (CIovec -> IO a) -> IO aSource

O(n) construction Use a ByteString with a function requiring a CIovec.

As with useAsCString and useAsCStringLen, this function makes a copy of the original ByteString via memcpy(3). The copy will be freed automatically. See unsafeUseAsCIovec for a zero-copying version.