From 0e5774aefc953d9e9f7cd270177512a819a80e4c Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Tue, 23 Jun 2009 13:38:18 +0000 Subject: [PATCH] add hFlushAll, flushes both read and write buffers --- GHC/IO/Handle.hs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/GHC/IO/Handle.hs b/GHC/IO/Handle.hs index f436f15..5becae8 100644 --- a/GHC/IO/Handle.hs +++ b/GHC/IO/Handle.hs @@ -23,7 +23,7 @@ module GHC.IO.Handle ( hFileSize, hSetFileSize, hIsEOF, hLookAhead, hSetBuffering, hSetBinaryMode, hSetEncoding, - hFlush, hDuplicate, hDuplicateTo, + hFlush, hFlushAll, hDuplicate, hDuplicateTo, hClose, hClose_help, @@ -282,6 +282,26 @@ hSetEncoding hdl encoding = do hFlush :: Handle -> IO () hFlush handle = wantWritableHandle "hFlush" handle flushWriteBuffer +-- | The action 'hFlushAll' @hdl@ flushes all buffered data in @hdl@, +-- including any buffered read data. Buffered read data is flushed +-- by seeking the file position back to the point before the bufferred +-- data was read, and hence only works if @hdl@ is seekable (see +-- 'hIsSeekable'). +-- +-- This operation may fail with: +-- +-- * 'isFullError' if the device is full; +-- +-- * 'isPermissionError' if a system resource limit would be exceeded. +-- It is unspecified whether the characters in the buffer are discarded +-- or retained under these circumstances; +-- +-- * 'isIllegalOperation' if @hdl@ has buffered read data, and is not +-- seekable. + +hFlushAll :: Handle -> IO () +hFlushAll handle = withHandle_ "hFlushAll" handle flushBuffer + -- ----------------------------------------------------------------------------- -- Repositioning Handles -- 1.7.10.4