LIB: give the buffer size in fallbackCopy a name

This commit is contained in:
Julian Ospald 2016-04-10 18:58:06 +02:00
parent 48edf7d47b
commit fb8d1d2e3a
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
1 changed files with 8 additions and 2 deletions

View File

@ -59,6 +59,10 @@ import Foreign.C.Error
, eINVAL
, eNOSYS
)
import Foreign.C.Types
(
CSize
)
import Foreign.Marshal.Alloc
(
allocaBytes
@ -377,12 +381,14 @@ unsafeCopyFile cm from@(_ :/ RegFile {}) to@(_ :/ Dir {}) fn
bracket (SPI.openFd dest SPI.WriteOnly (Just fileM)
SPI.defaultFileFlags)
SPI.closeFd
$ \dfd -> allocaBytes 8192 $ \buf ->
$ \dfd -> allocaBytes (fromIntegral bufSize) $ \buf ->
write' sfd dfd buf 0
where
bufSize :: CSize
bufSize = 8192
write' :: Fd -> Fd -> Ptr Word8 -> Int -> IO Int
write' sfd dfd buf totalsize = do
size <- SPB.fdReadBuf sfd buf 8192
size <- SPB.fdReadBuf sfd buf bufSize
if (size == 0)
then return $ fromIntegral totalsize
else do rsize <- SPB.fdWriteBuf dfd buf size