From: simonmar Date: Thu, 19 Jun 2003 13:04:52 +0000 (+0000) Subject: [project @ 2003-06-19 13:04:49 by simonmar] X-Git-Tag: nhc98-1-18-release~604 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=4a46c7689460b6b8f77fc4e8dca2026825cbef45;p=haskell-directory.git [project @ 2003-06-19 13:04:49 by simonmar] Following near-silence on the libraries list, add openBinaryFile :: FilePath -> IOMode -> IO Handle hSetBinaryMode :: Handle -> Bool -> IO () to System.IO. IOModeEx(..) and openFileEx are still available from IOExts (package lang), but are marked DEPRECATED. --- diff --git a/GHC/Handle.hs b/GHC/Handle.hs index eae9a3a..f638dff 100644 --- a/GHC/Handle.hs +++ b/GHC/Handle.hs @@ -34,7 +34,7 @@ module GHC.Handle ( ioe_closedHandle, ioe_EOF, ioe_notReadable, ioe_notWritable, stdin, stdout, stderr, - IOMode(..), IOModeEx(..), openFile, openFileEx, openFd, fdToHandle, + IOMode(..), openFile, openBinaryFile, openFd, fdToHandle, hFileSize, hIsEOF, isEOF, hLookAhead, hSetBuffering, hSetBinaryMode, hFlush, hDuplicate, hDuplicateTo, @@ -639,38 +639,25 @@ Two files are the same if they have the same absolute name. An implementation is free to impose stricter conditions. -} -data IOModeEx - = BinaryMode IOMode - | TextMode IOMode - deriving (Eq, Read, Show) - addFilePathToIOError fun fp (IOError h iot _ str _) = IOError h iot fun str (Just fp) openFile :: FilePath -> IOMode -> IO Handle openFile fp im = catch - (openFile' fp (if dEFAULT_OPEN_IN_BINARY_MODE - then BinaryMode im - else TextMode im)) + (openFile' fp im dEFAULT_OPEN_IN_BINARY_MODE) (\e -> ioError (addFilePathToIOError "openFile" fp e)) -openFileEx :: FilePath -> IOModeEx -> IO Handle -openFileEx fp m = +openBinaryFile :: FilePath -> IOMode -> IO Handle +openBinaryFile fp m = catch - (openFile' fp m) + (openFile' fp m True) (\e -> ioError (addFilePathToIOError "openFileEx" fp e)) - -openFile' filepath ex_mode = +openFile' filepath mode binary = withCString filepath $ \ f -> let - (mode, binary) = - case ex_mode of - BinaryMode bmo -> (bmo, True) - TextMode tmo -> (tmo, False) - oflags1 = case mode of ReadMode -> read_flags WriteMode -> write_flags diff --git a/System/IO.hs b/System/IO.hs index d6bc1ee..89220af 100644 --- a/System/IO.hs +++ b/System/IO.hs @@ -24,6 +24,7 @@ module System.IO ( stdin, stdout, stderr, -- :: Handle openFile, -- :: FilePath -> IOMode -> IO Handle + openBinaryFile, -- :: FilePath -> IOMode -> IO Handle hClose, -- :: Handle -> IO () hFileSize, -- :: Handle -> IO Integer hIsEOF, -- :: Handle -> IO Bool @@ -31,6 +32,7 @@ module System.IO ( hSetBuffering, -- :: Handle -> BufferMode -> IO () hGetBuffering, -- :: Handle -> IO BufferMode + hSetBinaryMode, -- :: Handle -> Bool -> IO () hFlush, -- :: Handle -> IO () hGetPosn, -- :: Handle -> IO HandlePosn hSetPosn, -- :: HandlePosn -> IO ()