Commit edf3f79d authored by simonmar's avatar simonmar
Browse files

[project @ 2001-08-28 11:12:09 by simonmar]

Add some tests for hGetBuf & hPutBuf
parent f81e778a
......@@ -11,3 +11,6 @@ test "hTell001" { myvtr("","","") }
test "hTell002" { myvtr("","","") }
test "performGC001" { myvtr("","","") }
test "trace001" { myvtr("","","") }
test "hGetBuf001" { myvtr("","","") }
test "hPutBuf001" { myvtr("","","") }
test "hPutBuf002" { myvtr("","","") }
import IO
import IOExts
import Foreign
import CForeign
main = do
h <- openFile "hGetBuf001.hs" ReadMode
let sz = 42
loop = do
b <- allocaBytes sz $ \ptr -> do
r <- hGetBuf h ptr sz
if (r == 0)
then return True
else do s <- peekCStringLen (ptr,r)
putStr s
return False
if b then return () else loop -- tail call
loop
import IO
import IOExts
import Foreign
import CForeign
main = do
h <- openFile "hGetBuf001.hs" ReadMode
let sz = 42
loop = do
b <- allocaBytes sz $ \ptr -> do
r <- hGetBuf h ptr sz
if (r == 0)
then return True
else do s <- peekCStringLen (ptr,r)
putStr s
return False
if b then return () else loop -- tail call
loop
import IO
import IOExts
import Foreign
import CForeign
main = withCStringLen "hello world\n" $ \(ptr,len) -> hPutBuf stdout ptr len
import IO
import IOExts
import Foreign
import CForeign
-- !!! this test failed to write anything in GHC 5.00.2
main = do
h <- openFile "hPutBuf002.out" ReadWriteMode
withCStringLen "hello world\n" $ \(ptr,len) -> hPutBuf h ptr len
hFileSize h >>= print
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment