[project @ 2001-07-31 11:59:08 by simonmar]
authorsimonmar <unknown>
Tue, 31 Jul 2001 11:59:08 +0000 (11:59 +0000)
committersimonmar <unknown>
Tue, 31 Jul 2001 11:59:08 +0000 (11:59 +0000)
merge fptools/ghc/lib/std/PrelHandle.hsc rev. 1.11

GHC/Handle.hsc

index c613d43..cc10334 100644 (file)
@@ -4,7 +4,7 @@
 #undef DEBUG
 
 -- -----------------------------------------------------------------------------
--- $Id: Handle.hsc,v 1.1 2001/06/28 14:15:03 simonmar Exp $
+-- $Id: Handle.hsc,v 1.2 2001/07/31 11:59:08 simonmar Exp $
 --
 -- (c) The University of Glasgow, 1994-2001
 --
@@ -22,9 +22,11 @@ module GHC.Handle (
 
   stdin, stdout, stderr,
   IOMode(..), IOModeEx(..), openFile, openFileEx, openFd,
-  hClose, hFileSize, hIsEOF, isEOF, hLookAhead, hSetBuffering, hSetBinaryMode,
+  hFileSize, hIsEOF, isEOF, hLookAhead, hSetBuffering, hSetBinaryMode,
   hFlush, 
 
+  hClose, hClose_help,
+
   HandlePosn(..), hGetPosn, hSetPosn,
   SeekMode(..), hSeek,
 
@@ -115,9 +117,7 @@ but we might want to revisit this in the future --SDM ].
 {-# INLINE withHandle #-}
 withHandle :: String -> Handle -> (Handle__ -> IO (Handle__,a)) -> IO a
 withHandle fun h@(FileHandle m)     act = withHandle' fun h m act
-withHandle fun h@(DuplexHandle r w) act = do 
-  withHandle' fun h r act
-  withHandle' fun h w act
+withHandle fun h@(DuplexHandle m _) act = withHandle' fun h m act
 
 withHandle' fun h m act = 
    block $ do
@@ -747,8 +747,9 @@ hClose h@(DuplexHandle r w) = do
                  haType = ClosedHandle
                 }
 
-hClose' h m =
-  withHandle__' "hClose" h m $ \ handle_ -> do
+hClose' h m = withHandle__' "hClose" h m $ hClose_help
+
+hClose_help handle_ =
   case haType handle_ of 
       ClosedHandle -> return handle_
       _ -> do
@@ -1146,18 +1147,20 @@ hIsTerminalDevice handle = do
 
 #ifdef _WIN32
 hSetBinaryMode handle bin = 
-  withHandle "hSetBinaryMode" handle $ \ handle_ ->
+  withAllHandles__ "hSetBinaryMode" handle $ \ handle_ ->
     do let flg | bin       = (#const O_BINARY)
               | otherwise = (#const O_TEXT)
        throwErrnoIfMinus1_ "hSetBinaryMode"
           (setmode (fromIntegral (haFD handle_)) flg)
-       return (handle_{haIsBin=bin}, ())
+       return handle_{haIsBin=bin}
+  return ()
 
 foreign import "setmode" setmode :: CInt -> CInt -> IO CInt
 #else
-hSetBinaryMode handle bin =
-  withHandle "hSetBinaryMode" handle $ \ handle_ ->
-    return (handle_{haIsBin=bin}, ())
+hSetBinaryMode handle bin = do
+  withAllHandles__ "hSetBinaryMode" handle $ \ handle_ ->
+    return handle_{haIsBin=bin}
+  return ()
 #endif
 
 -- -----------------------------------------------------------------------------