From: simonmar Date: Fri, 10 May 2002 14:52:00 +0000 (+0000) Subject: [project @ 2002-05-10 14:52:00 by simonmar] X-Git-Tag: nhc98-1-18-release~1023 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=b809a612e4b383f070052b843b0f39f520397a52;p=haskell-directory.git [project @ 2002-05-10 14:52:00 by simonmar] give slurpFile, hGetBuf and hPutBuf reasonable behaviour for zero-sized files --- diff --git a/GHC/IO.hs b/GHC/IO.hs index 32018e9..9467c53 100644 --- a/GHC/IO.hs +++ b/GHC/IO.hs @@ -607,7 +607,8 @@ hPutBuf :: Handle -- handle to write to -> Int -- number of bytes of data in buffer -> IO () hPutBuf handle ptr count - | count <= 0 = illegalBufferSize handle "hPutBuf" count + | count == 0 = return () + | count < 0 = illegalBufferSize handle "hPutBuf" count | otherwise = wantWritableHandle "hPutBuf" handle $ \ handle_@Handle__{ haFD=fd, haBuffer=ref, haIsStream=is_stream } -> do @@ -647,7 +648,8 @@ writeChunk fd ptr bytes = loop 0 bytes hGetBuf :: Handle -> Ptr a -> Int -> IO Int hGetBuf handle ptr count - | count <= 0 = illegalBufferSize handle "hGetBuf" count + | count == 0 = return 0 + | count < 0 = illegalBufferSize handle "hGetBuf" count | otherwise = wantReadableHandle "hGetBuf" handle $ \ handle_@Handle__{ haFD=fd, haBuffer=ref } -> do @@ -694,6 +696,7 @@ slurpFile fname = do ioError (userError "slurpFile: file too big") else do let sz_i = fromIntegral sz + if sz_i == 0 then return (nullPtr, 0) else do chunk <- mallocBytes sz_i r <- hGetBuf handle chunk sz_i hClose handle