[project @ 1998-08-24 19:12:06 by sof]
authorsof <unknown>
Mon, 24 Aug 1998 19:12:06 +0000 (19:12 +0000)
committersof <unknown>
Mon, 24 Aug 1998 19:12:06 +0000 (19:12 +0000)
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

index 99a62ed..4fa4a7d 100644 (file)
@@ -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