+\subsection{Changing echo status}
+%* *
+%*********************************************************
+
+\begin{code}
+hSetEcho :: Handle -> Bool -> IO ()
+hSetEcho hdl on = do
+ isT <- hIsTerminalDevice hdl
+ if not isT
+ then return ()
+ else do
+ htype <- readHandle hdl
+ case htype of
+ ErrorHandle ioError -> do
+ writeHandle hdl htype
+ fail ioError
+ ClosedHandle -> do
+ writeHandle hdl htype
+ ioe_closedHandle hdl
+ other -> do
+ rc <- _ccall_ setTerminalEcho (filePtr htype) (if on then 1 else 0)
+ writeHandle hdl htype
+ if rc /= -1
+ then return ()
+ else constructErrorAndFail "hSetEcho"
+
+hGetEcho :: Handle -> IO Bool
+hGetEcho hdl = do
+ isT <- hIsTerminalDevice hdl
+ if not isT
+ then return False
+ else do
+ htype <- readHandle hdl
+ case htype of
+ ErrorHandle ioError -> do
+ writeHandle hdl htype
+ fail ioError
+ ClosedHandle -> do
+ writeHandle hdl htype
+ ioe_closedHandle hdl
+ other -> do
+ rc <- _ccall_ getTerminalEcho (filePtr htype)
+ writeHandle hdl htype
+ case rc of
+ 1 -> return True
+ 0 -> return False
+ _ -> constructErrorAndFail "hSetEcho"
+
+hIsTerminalDevice :: Handle -> IO Bool
+hIsTerminalDevice hdl = do
+ htype <- readHandle hdl
+ case htype of
+ ErrorHandle ioError -> do
+ writeHandle hdl htype
+ fail ioError
+ ClosedHandle -> do
+ writeHandle hdl htype
+ ioe_closedHandle hdl
+ other -> do
+ rc <- _ccall_ isTerminalDevice (filePtr htype)
+ writeHandle hdl htype
+ case rc of
+ 1 -> return True
+ 0 -> return False
+ _ -> constructErrorAndFail "hIsTerminalDevice"
+\end{code}
+
+
+
+%*********************************************************
+%* *