@@ -48,34 +48,23 @@ import GHC.IO.Handle.Internals (wantWritableHandle)
4848import GHC.IO.Handle.Text (commitBuffer')
4949import GHC.IO.Handle.Types (BufferList(..), BufferMode(..), Handle__(..),
5050 Newline(..))
51+import System.IO (IOMode(..), openFile, withFile)
5152#endif
5253
5354-- | The 'readFile' function reads a file and returns the contents of
5455-- the file as a string. The entire file is read strictly, as with
5556-- 'getContents'.
5657readFile :: FilePath -> IO Text
57−#if __GLASGOW_HASKELL__ <= 610
58−readFile = fmap decodeUtf8 . B.readFile
59−#else
60−readFile = undefined
61−#endif
58+readFile name = openFile name ReadMode >>= hGetContents
6259
6360-- | Write a string to a file. The file is truncated to zero length
6461-- before writing begins.
6562writeFile :: FilePath -> Text -> IO ()
66−#if __GLASGOW_HASKELL__ <= 610
67−writeFile p = B.writeFile p . encodeUtf8
68−#else
69−writeFile = undefined
70−#endif
63+writeFile p = withFile p WriteMode . flip hPutStr
7164
7265-- | Write a string the end of a file.
7366appendFile :: FilePath -> Text -> IO ()
74−#if __GLASGOW_HASKELL__ <= 610
75−appendFile p = B.appendFile p . encodeUtf8
76−#else
77−appendFile = undefined
78−#endif
67+appendFile p = withFile p AppendMode . flip hPutStr
7968
8069-- | Read the remaining contents of a handle as a string.
8170hGetContents :: Handle -> IO Text
@@ -174,11 +163,7 @@ commitBuffer hdl !raw !sz !count flush release =
174163
175164-- | Write a string to a handle, followed by a newline.
176165hPutStrLn :: Handle -> Text -> IO ()
177−#if __GLASGOW_HASKELL__ <= 610
178−hPutStrLn h t = B.hPutStrLn h (encodeUtf8 t) >> hPutChar h '\n'
179−#else
180166hPutStrLn h t = hPutStr h t >> hPutChar h '\n'
181−#endif
182167
183168-- | The 'interact' function takes a function of type @Text -> Text@
184169-- as its argument. The entire input from the standard input device is