lazyReadChar :: Handle -> PrimIO String
lazyReadBlock handle =
- ioToST (readHandle handle) >>= \ htype ->
+ ioToST (readHandle handle) >>= \ htype ->
case htype of
-- There cannae be an ErrorHandle here
ClosedHandle ->
returnPrimIO (unpackPS some ++ more)
lazyReadLine handle =
- ioToST (readHandle handle) >>= \ htype ->
+ ioToST (readHandle handle) >>= \ htype ->
case htype of
-- There cannae be an ErrorHandle here
ClosedHandle ->
returnPrimIO (unpackPS some ++ more)
lazyReadChar handle =
- ioToST (readHandle handle) >>= \ htype ->
+ ioToST (readHandle handle) >>= \ htype ->
case htype of
-- There cannae be an ErrorHandle here
ClosedHandle ->
unsafeInterleavePrimIO (lazyReadChar handle)
>>= \ more ->
returnPrimIO (chr char : more)
+
\end{code}
writeHandle handle htype >>
fail (IOError (Just handle) IllegalOperation "handle is not open for writing")
other ->
+ {-
+ The code below is not correct for line-buffered terminal streams,
+ as the output stream is not flushed when terminal input is requested
+ again, just upon seeing a newline character. A temporary fix for the
+ most common line-buffered output stream, stdout, is to assume the
+ buffering it was given when created (no buffering). This is not
+ as bad as it looks, since stdio buffering sits underneath this.
+
+ ToDo: fix me
+ -}
getBufferMode other `thenIO_Prim` \ other ->
(case bufferMode other of
Just LineBuffering ->
- writeLines (filePtr other) str
+ writeChars (filePtr other) str
+ --writeLines (filePtr other) str
Just (BlockBuffering (Just size)) ->
writeBlocks (filePtr other) size str
Just (BlockBuffering Nothing) ->
((C# x):xs) ->
write_char arr# n x >>
- {- Flushing lines - should we bother? -}
- if n ==# bufLen {- || (chopOnNewLine && (x `eqChar#` '\n'#)) -} then
+ {- Flushing lines - should we bother? Yes, for line-buffered output. -}
+ if n ==# bufLen || (chopOnNewLine && (x `eqChar#` '\n'#)) then
_ccall_ writeFile arr fp (I# (n +# 1#)) >>= \ rc ->
if rc == 0 then
shoveString 0# xs