+{-# LANGUAGE CPP
+ , NoImplicitPrelude
+ , RecordWildCards
+ , NondecreasingIndentation
+ #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}
-{-# LANGUAGE NoImplicitPrelude, RecordWildCards #-}
-----------------------------------------------------------------------------
-- |
mb_exc <- hClose' h m
hClose_maybethrow mb_exc h
hClose h@(DuplexHandle _ r w) = do
- mb_exc1 <- hClose' h w
- mb_exc2 <- hClose' h r
- case mb_exc1 of
- Nothing -> return ()
- Just e -> hClose_maybethrow mb_exc2 h
+ excs <- mapM (hClose' h) [r,w]
+ hClose_maybethrow (listToMaybe (catMaybes excs)) h
hClose_maybethrow :: Maybe SomeException -> Handle -> IO ()
-hClose_maybethrow Nothing h = return ()
+hClose_maybethrow Nothing h = return ()
hClose_maybethrow (Just e) h = hClose_rethrow e h
hClose_rethrow :: SomeException -> Handle -> IO ()
posn <- IODevice.tell haDevice
- cbuf <- readIORef haCharBuffer
+ -- we can't tell the real byte offset if there are buffered
+ -- Chars, so must flush first:
+ flushCharBuffer handle_
+
bbuf <- readIORef haByteBuffer
- let real_posn
- | isWriteBuffer cbuf = posn + fromIntegral (bufR cbuf)
- | otherwise = posn - fromIntegral (bufR cbuf - bufL cbuf)
- - fromIntegral (bufR bbuf - bufL bbuf)
+ let real_posn
+ | isWriteBuffer bbuf = posn + fromIntegral (bufferElems bbuf)
+ | otherwise = posn - fromIntegral (bufferElems bbuf)
+ cbuf <- readIORef haCharBuffer
debugIO ("\nhGetPosn: (posn, real_posn) = " ++ show (posn, real_posn))
debugIO (" cbuf: " ++ summaryBuffer cbuf ++
" bbuf: " ++ summaryBuffer bbuf)
-- | Select binary mode ('True') or text mode ('False') on a open handle.
-- (See also 'openBinaryFile'.)
--
--- This has the same effect as calling 'hSetEncoding' with 'latin1', together
+-- This has the same effect as calling 'hSetEncoding' with 'char8', together
-- with 'hSetNewlineMode' with 'noNewlineTranslation'.
--
hSetBinaryMode :: Handle -> Bool -> IO ()