summaryrefslogtreecommitdiff
path: root/compiler/main
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2011-11-24 10:59:57 +0000
committerSimon Marlow <marlowsd@gmail.com>2011-11-24 14:56:30 +0000
commit3e8303c137e647c4db919f7c21396e1325b58731 (patch)
tree74f5ae95c3a25998194abc0e12214321d9561cf7 /compiler/main
parent86255c661a0c6f3c1756f4bedd0226e7cd631ad2 (diff)
downloadhaskell-3e8303c137e647c4db919f7c21396e1325b58731.tar.gz
copyFileWithHeader: write the header in UTF-8
Diffstat (limited to 'compiler/main')
-rw-r--r--compiler/main/SysTools.lhs14
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler/main/SysTools.lhs b/compiler/main/SysTools.lhs
index 00311597d8..4a51b313e2 100644
--- a/compiler/main/SysTools.lhs
+++ b/compiler/main/SysTools.lhs
@@ -582,10 +582,22 @@ copyWithHeader dflags purpose maybe_header from to = do
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
+ maybe (return ()) (header hout) maybe_header
hPutStr hout ls
hClose hout
hClose hin
+ where
+#if __GLASGOW_HASKELL__ >= 702
+ -- write the header string in UTF-8. The header is something like
+ -- {-# LINE "foo.hs" #-}
+ -- and we want to make sure a Unicode filename isn't mangled.
+ header h str = do
+ hSetEncoding h utf8
+ hPutStr h str
+ hSetBinaryMode h True
+#else
+ header h str = hPutStr h str
+#endif
-- | read the contents of the named section in an ELF object as a
-- String.