From: simonmar Date: Thu, 31 May 2001 10:03:35 +0000 (+0000) Subject: [project @ 2001-05-31 10:03:35 by simonmar] X-Git-Tag: Approximately_9120_patches~1834 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=3760799b1e8359eab25d57f633711577a8c1db02;p=ghc-hetmet.git [project @ 2001-05-31 10:03:35 by simonmar] - don't put a TTY into RAW mode if the handle is an output-only handle (so if you set stdout to NoBuffering and leave stdin as it is, you don't lose TTY processing on stdin). - some cleanups. --- diff --git a/ghc/lib/std/PrelHandle.hsc b/ghc/lib/std/PrelHandle.hsc index ce13119..0452fc1 100644 --- a/ghc/lib/std/PrelHandle.hsc +++ b/ghc/lib/std/PrelHandle.hsc @@ -4,7 +4,7 @@ #undef DEBUG -- ----------------------------------------------------------------------------- --- $Id: PrelHandle.hsc,v 1.6 2001/05/30 16:39:22 sewardj Exp $ +-- $Id: PrelHandle.hsc,v 1.7 2001/05/31 10:03:35 simonmar Exp $ -- -- (c) The University of Glasgow, 1994-2001 -- @@ -266,6 +266,12 @@ ioe_notSeekable = ioException (IOError Nothing IllegalOperation "" "handle is not seekable" Nothing) +ioe_bufsiz :: Int -> IO a +ioe_bufsiz n = ioException + (IOError Nothing InvalidArgument "hSetBuffering" + ("illegal buffer size " ++ showsPrec 9 n []) Nothing) + -- 9 => should be parens'ified. + -- ----------------------------------------------------------------------------- -- Handle Finalizers @@ -864,22 +870,16 @@ hSetBuffering handle mode = -- for input terminals we need to put the terminal into -- cooked or raw mode depending on the type of buffering. is_tty <- fdIsTTY (haFD handle_) - when is_tty $ + when (is_tty && isReadableHandleType (haType handle_)) $ case mode of NoBuffering -> setCooked (haFD handle_) False _ -> setCooked (haFD handle_) True - + -- throw away spare buffers, they might be the wrong size writeIORef (haBuffers handle_) BufferListNil return (handle_{ haBufferMode = mode }) -ioe_bufsiz n - = ioException (IOError Nothing InvalidArgument "hSetBuffering" - ("illegal buffer size " ++ showsPrec 9 n []) - -- 9 => should be parens'ified. - Nothing) - -- ----------------------------------------------------------------------------- -- hFlush @@ -1049,12 +1049,7 @@ hIsReadable handle = case haType handle_ of ClosedHandle -> ioe_closedHandle SemiClosedHandle -> ioe_closedHandle - htype -> return (isReadable htype) - where - isReadable ReadHandle = True - isReadable (ReadSideHandle _) = True - isReadable ReadWriteHandle = True - isReadable _ = False + htype -> return (isReadableHandleType htype) hIsWritable :: Handle -> IO Bool hIsWritable (DuplexHandle _ _) = return False @@ -1063,12 +1058,7 @@ hIsWritable handle = case haType handle_ of ClosedHandle -> ioe_closedHandle SemiClosedHandle -> ioe_closedHandle - htype -> return (isWritable htype) - where - isWritable AppendHandle = True - isWritable WriteHandle = True - isWritable ReadWriteHandle = True - isWritable _ = False + htype -> return (isWritableHandleType htype) -- Querying how a handle buffers its data: diff --git a/ghc/lib/std/PrelIOBase.lhs b/ghc/lib/std/PrelIOBase.lhs index 351f271..148ae00 100644 --- a/ghc/lib/std/PrelIOBase.lhs +++ b/ghc/lib/std/PrelIOBase.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: PrelIOBase.lhs,v 1.40 2001/05/22 19:25:49 qrczak Exp $ +% $Id: PrelIOBase.lhs,v 1.41 2001/05/31 10:03:35 simonmar Exp $ % % (c) The University of Glasgow, 1994-2001 % @@ -236,6 +236,16 @@ data HandleType | ReadWriteHandle | ReadSideHandle !(MVar Handle__) -- read side of a duplex handle +isReadableHandleType ReadHandle = True +isReadableHandleType ReadWriteHandle = True +isReadableHandleType (ReadSideHandle _) = True +isReadableHandleType _ = False + +isWritableHandleType AppendHandle = True +isWritableHandleType WriteHandle = True +isWritableHandleType ReadWriteHandle = True +isWritableHandleType _ = False + -- File names are specified using @FilePath@, a OS-dependent -- string that (hopefully, I guess) maps to an accessible file/object.