#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
--
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,
{-# 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
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
#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
-- -----------------------------------------------------------------------------