From: sof Date: Mon, 24 Aug 1998 19:12:06 +0000 (+0000) Subject: [project @ 1998-08-24 19:12:06 by sof] X-Git-Tag: Approx_2487_patches~293 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=a13ea2a1a1db960fc4ca80eaa290d219b53eac7c;p=ghc-hetmet.git [project @ 1998-08-24 19:12:06 by sof] New functions: hFillBuf :: Handle -> Addr -> Int -> IO Int hFillBufBA :: Handle -> ByteArray Int -> Int -> IO Int reading a sequence of a bytes into a chunk of memory. --- diff --git a/ghc/lib/std/PrelHandle.lhs b/ghc/lib/std/PrelHandle.lhs index 99a62ed..4fa4a7d 100644 --- a/ghc/lib/std/PrelHandle.lhs +++ b/ghc/lib/std/PrelHandle.lhs @@ -830,6 +830,36 @@ slurpFile fname = do then constructErrorAndFail "slurpFile" else return (chunk, rc) +hFillBufBA :: Handle -> ByteArray Int -> Int -> IO Int +hFillBufBA handle buf sz + | sz <= 0 = fail (IOError (Just handle) + InvalidArgument + "hFillBufBA" + ("illegal buffer size " ++ showsPrec 9 sz [])) -- 9 => should be parens'ified. + | otherwise = do + handle_ <- wantReadableHandle "hFillBufBA" handle + let fo = haFO__ handle_ + rc <- mayBlock fo (_ccall_ readChunk fo buf sz) -- ConcHask: UNSAFE, may block. + writeHandle handle handle_ + if rc >= 0 + then return rc + else constructErrorAndFail "hFillBufBA" + +hFillBuf :: Handle -> Addr -> Int -> IO Int +hFillBuf handle buf sz + | sz <= 0 = fail (IOError (Just handle) + InvalidArgument + "hFillBuf" + ("illegal buffer size " ++ showsPrec 9 sz [])) -- 9 => should be parens'ified. + | otherwise = do + handle_ <- wantReadableHandle "hFillBuf" handle + let fo = haFO__ handle_ + rc <- mayBlock fo (_ccall_ readChunk fo buf sz) -- ConcHask: UNSAFE, may block. + writeHandle handle handle_ + if rc >= 0 + then return rc + else constructErrorAndFail "hFillBuf" + \end{code} The @hPutBuf hdl buf len@ action writes an already packed sequence of