really fix foreign C functions filename encodings
GHC should probably export withFilePath.
This commit is contained in:
parent
dc682e53a2
commit
56470ce3e5
2 changed files with 13 additions and 3 deletions
|
@ -16,6 +16,11 @@ module Utility.Touch (
|
|||
import Foreign
|
||||
import Foreign.C
|
||||
import Control.Monad (when)
|
||||
import GHC.IO.Encoding (getFileSystemEncoding)
|
||||
import GHC.Foreign as GHC
|
||||
|
||||
withFilePath :: FilePath -> (CString -> IO a) -> IO a
|
||||
withFilePath fp f = getFileSystemEncoding >>= \enc -> GHC.withCString enc fp f
|
||||
|
||||
newtype TimeSpec = TimeSpec CTime
|
||||
|
||||
|
@ -64,7 +69,7 @@ foreign import ccall "utimensat"
|
|||
|
||||
touchBoth file atime mtime follow =
|
||||
allocaArray 2 $ \ptr ->
|
||||
withCAString file $ \f -> do
|
||||
withFilePath file $ \f -> do
|
||||
pokeArray ptr [atime, mtime]
|
||||
r <- c_utimensat at_fdcwd f ptr flags
|
||||
when (r /= 0) $ throwErrno "touchBoth"
|
||||
|
@ -101,7 +106,7 @@ foreign import ccall "lutimes"
|
|||
|
||||
touchBoth file atime mtime follow =
|
||||
allocaArray 2 $ \ptr ->
|
||||
withCAString file $ \f -> do
|
||||
withFilePath file $ \f -> do
|
||||
pokeArray ptr [atime, mtime]
|
||||
r <- syscall f ptr
|
||||
if (r /= 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue