System.IO

module System.IO(module IO,module System.IO) where
import IO
import System(system)
import MonadicIO0(primOpenFile,primHSetBinaryMode)

openBinaryFile :: FilePath -> IOMode -> IO Handle
openBinaryFile path mode = {-fmap Handle-} (primOpenFile path (4+fromEnum mode))
                            `ioeAddPath` path

hIsTerminalDevice h = return False

withFile,withBinaryFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r
withFile       path mode = bracket (openFile       path mode) hClose
withBinaryFile path mode = bracket (openBinaryFile path mode) hClose

hSetBinaryMode :: Handle -> Bool -> IO ()
hSetBinaryMode h b = primHSetBinaryMode h b
--hSetBinaryMode h b = error "System.IO.hSetBinaryMode not implemented"

-- * Unicode encoding/decoding

hSetEncoding :: Handle -> TextEncoding -> IO ()
hSetEncoding _ _ = return ()  -- !! not implemented

-- * Unicode encodings

newtype TextEncoding = TextEncoding String deriving Show
localeEncoding = utf8 -- hmm
utf8 = TextEncoding "UTF-8" -- hmm

mkTextEncoding :: String -> IO TextEncoding
mkTextEncoding = return . TextEncoding

-- * Terminal operations

hSetEcho :: Handle -> Bool -> IO ()
hSetEcho h b | h `elem` [stdin,stdout] = -- !!!
    do system ("stty "++mode) -- !!
       return ()
  where mode = if b then "echo" else "-echo"