X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FConsoleHandler.hs;h=223a2bb8c5af5bd8d3130d611a2e24abce147e7b;hb=8bb6db3e726aa1eeb6d512bfb5165f9f9f92210c;hp=cabaa53c497a162ae593b2e7107c1b5aebf3a3e8;hpb=9a101ce92ae850645471b8b5221215cdc5f916de;p=ghc-base.git diff --git a/GHC/ConsoleHandler.hs b/GHC/ConsoleHandler.hs index cabaa53..223a2bb 100644 --- a/GHC/ConsoleHandler.hs +++ b/GHC/ConsoleHandler.hs @@ -1,4 +1,5 @@ -{-# OPTIONS_GHC -cpp #-} +{-# LANGUAGE CPP #-} + ----------------------------------------------------------------------------- -- | -- Module : GHC.ConsoleHandler @@ -18,7 +19,6 @@ module GHC.ConsoleHandler #if !defined(mingw32_HOST_OS) && !defined(__HADDOCK__) where -import Prelude -- necessary to get dependencies right #else /* whole file */ ( Handler(..) , installHandler @@ -27,17 +27,23 @@ import Prelude -- necessary to get dependencies right ) where {- -#include "Signals.h" +#include "rts/Signals.h" -} -import Prelude -- necessary to get dependencies right - import Foreign import Foreign.C -import GHC.IOBase +import GHC.IO.FD +import GHC.IO.Exception +import GHC.IO.Handle.Types +import GHC.IO.Handle.Internals import GHC.Conc -import GHC.Handle import Control.Concurrent.MVar +import Data.Typeable + +#ifdef mingw32_HOST_OS +import Data.Maybe +import GHC.Base +#endif data Handler = Default @@ -134,10 +140,16 @@ foreign import ccall unsafe "RtsExternal.h rts_ConsoleHandlerDone" flushConsole :: Handle -> IO () flushConsole h = - wantReadableHandle "flushConsole" h $ \ h_ -> - throwErrnoIfMinus1Retry_ "flushConsole" - (flush_console_fd (fromIntegral (haFD h_))) + wantReadableHandle_ "flushConsole" h $ \ Handle__{haDevice=dev} -> + case cast dev of + Nothing -> ioException $ + IOError (Just h) IllegalOperation "flushConsole" + "handle is not a file descriptor" Nothing Nothing + Just fd -> do + throwErrnoIfMinus1Retry_ "flushConsole" $ + flush_console_fd (fdFD fd) foreign import ccall unsafe "consUtils.h flush_input_console__" flush_console_fd :: CInt -> IO CInt + #endif /* mingw32_HOST_OS */