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