diff options
author | sof <unknown> | 1998-11-23 15:44:25 +0000 |
---|---|---|
committer | sof <unknown> | 1998-11-23 15:44:25 +0000 |
commit | bbe9c55569ffa1ea660a02d7349afb4ba659072d (patch) | |
tree | 7b8e6b964012cdda16a1bdf2b092719cc0d04af7 /ghc/lib/std/cbits/flushFile.lc | |
parent | 9a13d5c84f7467ea29fc7e50b7257585e9c1cee7 (diff) | |
download | haskell-bbe9c55569ffa1ea660a02d7349afb4ba659072d.tar.gz |
[project @ 1998-11-23 15:44:21 by sof]
Extend hConnectTo to also allow output handles to be connected, i.e.,
h1 <- openFile "foo" WriteMode
h2 <- openFile "bar" WriteMode
hConnectTo h1 h2
will cause h1's buffer to be flushed when h2's buffer overflows
(and it is just about to be flushed.) The implementation is currently
not as lazy as that, it flushes h1's buffer regardless of whether h2's
buffer overflows or not.
This is used to connect 'stderr' and 'stdout', i.e., output on
'stderr' will now cause 'stdout' output to (first) be flushed.
Diffstat (limited to 'ghc/lib/std/cbits/flushFile.lc')
-rw-r--r-- | ghc/lib/std/cbits/flushFile.lc | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/ghc/lib/std/cbits/flushFile.lc b/ghc/lib/std/cbits/flushFile.lc index 595dfc01ac..6fa7888ff5 100644 --- a/ghc/lib/std/cbits/flushFile.lc +++ b/ghc/lib/std/cbits/flushFile.lc @@ -80,8 +80,21 @@ StgForeignObj ptr; return 0; } - -\end{code} +void +flushConnectedHandle(ptr) +StgForeignObj ptr; +{ + StgInt rc; + IOFileObject* fo = (IOFileObject*)ptr; + /* if the stream is connected to an output stream, flush it first */ + if ( fo->connectedTo != NULL && fo->connectedTo->fd != -1 && + (fo->connectedTo->flags & FILEOBJ_WRITE) ) { + rc = flushBuffer((StgForeignObj)fo->connectedTo); + } + /* Willfully ignore return code for now */ + return; +} +\end{code} |