summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-06-20 13:15:59 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-06-20 13:15:59 -0400
commit483b1b08c6fad82d5e17aaaded398bdad94124f1 (patch)
tree1dc6d610a7947c2169d51e9ef7b575e315f8d34c /Utility
parent5580af5789427fc5fd7cd74fd4a2529668621a68 (diff)
parent75b6ee81f9d9b921106c829380e30445415ec2f7 (diff)
Merge branch 'master' into watch
Diffstat (limited to 'Utility')
-rw-r--r--Utility/FileSystemEncoding.hs16
-rw-r--r--Utility/Gpg.hs2
2 files changed, 16 insertions, 2 deletions
diff --git a/Utility/FileSystemEncoding.hs b/Utility/FileSystemEncoding.hs
index cf1a6a731..d027ede48 100644
--- a/Utility/FileSystemEncoding.hs
+++ b/Utility/FileSystemEncoding.hs
@@ -13,6 +13,8 @@ import Foreign.C
import System.IO
import System.IO.Unsafe
import qualified Data.Hash.MD5 as MD5
+import Data.Word
+import Data.Bits.Utils
{- Sets a Handle to use the filesystem encoding. This causes data
- written or read from it to be encoded/decoded the same
@@ -29,7 +31,7 @@ withFilePath :: FilePath -> (CString -> IO a) -> IO a
withFilePath fp f = Encoding.getFileSystemEncoding
>>= \enc -> GHC.withCString enc fp f
-{- Encodes a FilePath into a Str, applying the filesystem encoding.
+{- Encodes a FilePath into a Md5.Str, applying the filesystem encoding.
-
- This use of unsafePerformIO is belived to be safe; GHC's interface
- only allows doing this conversion with CStrings, and the CString buffer
@@ -41,3 +43,15 @@ encodeFilePath :: FilePath -> MD5.Str
encodeFilePath fp = MD5.Str $ unsafePerformIO $ do
enc <- Encoding.getFileSystemEncoding
GHC.withCString enc fp $ GHC.peekCString Encoding.char8
+
+{- Converts a [Word8] to a FilePath, encoding using the filesystem encoding.
+ -
+ - w82c produces a String, which may contain Chars that are invalid
+ - unicode. From there, this is really a simple matter of applying the
+ - file system encoding, only complicated by GHC's interface to doing so.
+ -}
+{-# NOINLINE encodeW8 #-}
+encodeW8 :: [Word8] -> FilePath
+encodeW8 w8 = unsafePerformIO $ do
+ enc <- Encoding.getFileSystemEncoding
+ GHC.withCString Encoding.char8 (w82s w8) $ GHC.peekCString enc
diff --git a/Utility/Gpg.hs b/Utility/Gpg.hs
index ff6735ba5..e13afe5d4 100644
--- a/Utility/Gpg.hs
+++ b/Utility/Gpg.hs
@@ -7,7 +7,7 @@
module Utility.Gpg where
-import qualified Data.ByteString.Lazy.Char8 as L
+import qualified Data.ByteString.Lazy as L
import System.Posix.Types
import Control.Applicative
import Control.Concurrent