X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FIO%2FHandle%2FText.hs;h=cf2541f65e1072c9723bc507ebdc6004e17c20d4;hb=ed8788054ed764f873d43a88fd3ea4ab74373dc1;hp=745dc183be06dcc7b2ff2e00f3ffd99932cad1c9;hpb=bad25ed6cb9b939d786e53d3074f0cd4f869af28;p=ghc-base.git diff --git a/GHC/IO/Handle/Text.hs b/GHC/IO/Handle/Text.hs index 745dc18..cf2541f 100644 --- a/GHC/IO/Handle/Text.hs +++ b/GHC/IO/Handle/Text.hs @@ -861,7 +861,7 @@ bufReadEmpty h_@Handle__{..} bufReadNonEmpty h_ buf' ptr so_far count where loop :: FD -> Int -> Int -> IO Int - loop fd off bytes | bytes <= 0 = return off + loop fd off bytes | bytes <= 0 = return (so_far + off) loop fd off bytes = do r <- RawIO.read (fd::FD) (ptr `plusPtr` off) (fromIntegral bytes) if r == 0 @@ -891,9 +891,9 @@ bufReadEmpty h_@Handle__{..} hGetBufSome :: Handle -> Ptr a -> Int -> IO Int hGetBufSome h ptr count | count == 0 = return 0 - | count < 0 = illegalBufferSize h "hGetBuf" count + | count < 0 = illegalBufferSize h "hGetBufSome" count | otherwise = - wantReadableHandle_ "hGetBuf" h $ \ h_@Handle__{..} -> do + wantReadableHandle_ "hGetBufSome" h $ \ h_@Handle__{..} -> do flushCharReadBuffer h_ buf@Buffer{ bufSize=sz } <- readIORef haByteBuffer if isEmptyBuffer buf @@ -903,7 +903,10 @@ hGetBufSome h ptr count if r == 0 then return 0 else do writeIORef haByteBuffer buf' - bufReadNBNonEmpty h_ buf' (castPtr ptr) 0 count + bufReadNBNonEmpty h_ buf' (castPtr ptr) 0 (min r count) + -- new count is (min r count), so + -- that bufReadNBNonEmpty will not + -- issue another read. else bufReadNBEmpty h_ buf (castPtr ptr) 0 count