#undef DEBUG_DUMP
--- -----------------------------------------------------------------------------
--- $Id: IO.hs,v 1.5 2002/02/11 12:28:31 simonmar Exp $
+-----------------------------------------------------------------------------
+-- |
+-- Module : GHC.IO
+-- Copyright : (c) The University of Glasgow, 1992-2001
+-- License : see libraries/base/LICENSE
+--
+-- Maintainer : libraries@haskell.org
+-- Stability : internal
+-- Portability : non-portable
--
--- (c) The University of Glasgow, 1992-2001
+-- String I\/O functions
--
+-----------------------------------------------------------------------------
module GHC.IO (
hWaitForInput, hGetChar, hGetLine, hGetContents, hPutChar, hPutStr,
unpackAcc :: RawBuffer -> Int -> Int -> [Char] -> IO [Char]
-unpackAcc buf r 0 acc = return ""
+unpackAcc buf r 0 acc = return acc
unpackAcc buf (I# r) (I# len) acc = IO $ \s -> unpack acc (len -# 1#) s
where
unpack acc i s
-> 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
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
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