% ------------------------------------------------------------------------------
-% $Id: PrelIOBase.lhs,v 1.39 2001/05/22 15:06:47 simonmar Exp $
+% $Id: PrelIOBase.lhs,v 1.42 2001/06/01 13:06:01 sewardj Exp $
%
% (c) The University of Glasgow, 1994-2001
%
module PrelIOBase where
import PrelST
-import PrelRead
import PrelArr
import PrelBase
import PrelNum -- To get fromInteger etc, needed because of -fno-implicit-prelude
import PrelMaybe ( Maybe(..) )
import PrelShow
import PrelList
+import PrelRead
import PrelDynamic
-- ---------------------------------------------------------------------------
= Handle__ {
haFD :: !FD,
haType :: HandleType,
+ haIsBin :: Bool,
haBufferMode :: BufferMode,
haFilePath :: FilePath,
haBuffer :: !(IORef Buffer),
bufferEmpty :: Buffer -> Bool
bufferEmpty Buffer{ bufRPtr=r, bufWPtr=w } = r == w
-bufferEmpty _other = False
-- only makes sense for a write buffer
bufferFull :: Buffer -> Bool
| 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.
data BufferMode
= NoBuffering | LineBuffering | BlockBuffering (Maybe Int)
- deriving (Eq, Ord, Show, Read)
+ deriving (Eq, Ord, Read, Show)
-- ---------------------------------------------------------------------------
-- IORefs
showHdl (haType hdl_)
(showString "loc=" . showString (haFilePath hdl_) . showChar ',' .
showString "type=" . showsPrec p (haType hdl_) . showChar ',' .
+ showString "binary=" . showsPrec p (haIsBin hdl_) . showChar ',' .
showString "buffering=" . showBufMode (unsafePerformIO (readIORef (haBuffer hdl_))) (haBufferMode hdl_) . showString "}" )
where
showHdl :: HandleType -> ShowS -> ShowS