Commit 93918b1b authored by ttuegel's avatar ttuegel
Browse files

D.Compat.CreatePipe: use locale encoding

Issue #1895. `createPipe` opened handles in binary mode by default,
which mangles text encoded for the current locale. Now, `hSetEncoding`
is called on the new handles. This requires `base >= 4.2`.
parent 5c70361b
......@@ -127,7 +127,7 @@ source-repository head
library
build-depends:
base >= 4 && < 5,
base >= 4.2 && < 5,
deepseq >= 1.3 && < 1.4,
filepath >= 1 && < 1.4,
directory >= 1 && < 1.3,
......
{-# LANGUAGE CPP, ForeignFunctionInterface #-}
module Distribution.Compat.CreatePipe (createPipe) where
import System.IO (Handle)
import System.IO (Handle, hSetEncoding, localeEncoding)
-- The mingw32_HOST_OS CPP macro is GHC-specific
#if mingw32_HOST_OS
......@@ -31,6 +31,8 @@ createPipe = do
return (readfd, writefd)
(do readh <- fdToHandle readfd ReadMode
writeh <- fdToHandle writefd WriteMode
hSetEncoding readh localeEncoding
hSetEncoding writeh localeEncoding
return (readh, writeh)) `onException` (close readfd >> close writefd)
where
fdToHandle :: CInt -> IOMode -> IO Handle
......@@ -51,5 +53,7 @@ createPipe = do
(readfd, writefd) <- Posix.createPipe
readh <- fdToHandle readfd
writeh <- fdToHandle writefd
hSetEncoding readh localeEncoding
hSetEncoding writeh localeEncoding
return (readh, writeh)
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment