summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--byterun/io.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/byterun/io.c b/byterun/io.c
index f473ce7d2..85f162aa2 100644
--- a/byterun/io.c
+++ b/byterun/io.c
@@ -172,12 +172,19 @@ again:
/* Attempt to flush the buffer. This will make room in the buffer for
at least one character. Returns true if the buffer is empty at the
- end of the flush, or false if some data remains in the buffer. */
+ end of the flush, or false if some data remains in the buffer.
+
+ If the channel is closed, DO NOT raise a "bad file descriptor"
+ exception, but do nothing (the buffer is already empty). See
+ the "at_exit" line of stdlib/format.ml for a good reason to avoid
+ the exception.
+ */
CAMLexport int flush_partial(struct channel *channel)
{
int towrite, written;
+ if (channel->fd == -1) return 1;
towrite = channel->curr - channel->buff;
if (towrite > 0) {
written = do_write(channel->fd, channel->buff, towrite);