copyFileWithHeader: use binary Handles
authorSimon Marlow <marlowsd@gmail.com>
Mon, 15 Jun 2009 11:05:45 +0000 (11:05 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Mon, 15 Jun 2009 11:05:45 +0000 (11:05 +0000)
Fixes failure when Haddocking Data.Monoid in libraries/base

compiler/main/SysTools.lhs

index a64d73e..357616b 100644 (file)
@@ -420,12 +420,13 @@ copyWithHeader :: DynFlags -> String -> Maybe String -> FilePath -> FilePath
 copyWithHeader dflags purpose maybe_header from to = do
   showPass dflags purpose
 
-  h <- openFile to WriteMode
-  ls <- readFile from -- inefficient, but it'll do for now.
-                      -- ToDo: speed up via slurping.
-  maybe (return ()) (hPutStr h) maybe_header
-  hPutStr h ls
-  hClose h
+  hout <- openBinaryFile to   WriteMode
+  hin  <- openBinaryFile from ReadMode
+  ls <- hGetContents hin -- inefficient, but it'll do for now. ToDo: speed up
+  maybe (return ()) (hPutStr hout) maybe_header
+  hPutStr hout ls
+  hClose hout
+  hClose hin
 
 getExtraViaCOpts :: DynFlags -> IO [String]
 getExtraViaCOpts dflags = do