module System.Posix.IO.Extra(writev, pwrite, pread) where
import Foreign
import Foreign.C
import Control.Monad
import System.Posix.Types
foreign import ccall safe "writev" cwritev :: Fd -> Ptr () -> CInt -> IO ByteCount
writev :: Fd -> [(Ptr a, Int)] -> IO ByteCount
writev fd lst = do
let len = length lst
allocaBytes (((8)) * len) $ \iovs -> do
let w i (p,pl) = do let iov = plusPtr iovs (((8)) * i)
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) iov p
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) iov pl
zipWithM_ w [0..] lst
throwErrnoIfMinus1Retry "writev" $ cwritev fd iovs $ fromIntegral len
foreign import ccall safe pwrite64 :: Fd -> Ptr a -> CSize -> COff -> IO ByteCount
foreign import ccall safe pread64 :: Fd -> Ptr a -> CSize -> COff -> IO ByteCount
pwrite :: Fd -> Ptr a -> Int -> COff -> IO ByteCount
pwrite fd ptr len off = throwErrnoIfMinus1Retry "pwrite" $ pwrite64 fd ptr (fromIntegral len) off
pread :: Fd -> Ptr a -> Int -> COff -> IO ByteCount
pread fd ptr len off = throwErrnoIfMinus1Retry "pread" $ pread64 fd ptr (fromIntegral len) off