Test Trac #5962
[packages/base.git] / tests / hGetBuf002.hs
1 import System.IO
2 import Foreign
3 import Foreign.C
4
5 main = do test True; test False
6
7 test blocking = do
8 h <- openBinaryFile "hGetBuf002.hs" ReadMode
9
10 let sz = 42
11 loop = do
12 b <- allocaBytes sz $ \ptr -> do
13 r <- (if blocking then hGetBuf else hGetBufNonBlocking) h ptr sz
14 if (r == 0)
15 then return True
16 else do s <- peekCStringLen (ptr,r)
17 putStr s
18 return False
19 if b then return () else loop -- tail call
20
21 loop
22