From 789254747bceeaac004236275a6c1906f859945a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Mar 2012 18:52:03 -0400 Subject: refactor --- Utility/FileSystemEncoding.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Utility/FileSystemEncoding.hs (limited to 'Utility/FileSystemEncoding.hs') diff --git a/Utility/FileSystemEncoding.hs b/Utility/FileSystemEncoding.hs new file mode 100644 index 000000000..6970a10de --- /dev/null +++ b/Utility/FileSystemEncoding.hs @@ -0,0 +1,18 @@ +{- File system encoding handling. + - + - Copyright 2012 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Utility.FileSystemEncoding where + +import GHC.IO.Encoding (getFileSystemEncoding) +import GHC.Foreign as GHC + +{- Marshal a Haskell FilePath into a NUL terminated C string using temporary + - storage. The FilePath is encoded using the filesystem encoding, + - reversing the decoding that should have been done when the FilePath + - was obtained. -} +withFilePath :: FilePath -> (CString -> IO a) -> IO a +withFilePath fp f = getFileSystemEncoding >>= \enc -> GHC.withCString enc fp f -- cgit v1.2.3