Fix encoding issues with realPath

This commit is contained in:
hasufell 2016-04-04 03:06:22 +02:00
parent 3a52a9ea4b
commit c7229061d0
1 changed files with 8 additions and 5 deletions

View File

@ -65,6 +65,8 @@ import Data.List
import Data.Maybe import Data.Maybe
import Foreign.C.Error import Foreign.C.Error
import Foreign.C.String import Foreign.C.String
import GHC.Foreign as GHC
import GHC.IO.Encoding (getFileSystemEncoding)
import Foreign.Marshal.Alloc(allocaBytes) import Foreign.Marshal.Alloc(allocaBytes)
import Language.Haskell.TH import Language.Haskell.TH
import HPath.Foreign import HPath.Foreign
@ -307,9 +309,10 @@ foreign import ccall "realpath"
-- like canonicalizePath, but uses realpath(3) -- like canonicalizePath, but uses realpath(3)
realPath :: String -> IO String realPath :: String -> IO String
realPath inp = do realPath inp = do
allocaBytes pathMax $ \tmp -> do encoding <- getFileSystemEncoding
void $ withCString inp allocaBytes pathMax $ \tmp -> do
$ \cstr -> throwErrnoIfNull "realpath" void $ GHC.withCString encoding inp
$ c_realpath cstr tmp $ \cstr -> throwErrnoIfNull "realpath"
peekCAString tmp $ c_realpath cstr tmp
GHC.peekCString encoding tmp