From a13ea2a1a1db960fc4ca80eaa290d219b53eac7c Mon Sep 17 00:00:00 2001 From: sof Date: Mon, 24 Aug 1998 19:12:06 +0000 Subject: [PATCH] [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. --- ghc/lib/std/PrelHandle.lhs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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 -- 1.7.10.4