[project @ 2001-07-31 11:06:00 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / PrelIOBase.lhs
index 918d3ed..9f36163 100644 (file)
@@ -1,5 +1,5 @@
 % ------------------------------------------------------------------------------
-% $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
 
 -- ---------------------------------------------------------------------------
@@ -153,6 +153,7 @@ data Handle__
   = Handle__ {
       haFD         :: !FD,
       haType        :: HandleType,
+      haIsBin       :: Bool,
       haBufferMode  :: BufferMode,
       haFilePath    :: FilePath,
       haBuffer     :: !(IORef Buffer),
@@ -219,7 +220,6 @@ bufferIsWritable _other = False
 
 bufferEmpty :: Buffer -> Bool
 bufferEmpty Buffer{ bufRPtr=r, bufWPtr=w } = r == w
-bufferEmpty _other = False
 
 -- only makes sense for a write buffer
 bufferFull :: Buffer -> Bool
@@ -237,6 +237,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.
 
@@ -284,7 +294,7 @@ type FilePath = String
 
 data BufferMode  
  = NoBuffering | LineBuffering | BlockBuffering (Maybe Int)
-   deriving (Eq, Ord, Show, Read)
+   deriving (Eq, Ord, Read, Show)
 
 -- ---------------------------------------------------------------------------
 -- IORefs
@@ -343,6 +353,7 @@ showHandle p h =
     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