aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/Temp.hsc
diff options
context:
space:
mode:
authorGravatar Max Bolingbroke <batterseapower@hotmail.com>2011-05-14 22:45:27 +0100
committerGravatar Max Bolingbroke <batterseapower@hotmail.com>2011-05-14 22:45:27 +0100
commitbb8a27d14a63fcd126a924d32c69b7694ea709d9 (patch)
treefc8fd365f738a6f77bc31a96efd470fbf2bd51dc /System/Posix/Temp.hsc
parentb7b180d23472dca03fb4c809cd86bcd6d3f01ea9 (diff)
Improved Unicode support in the light of PEP383
Diffstat (limited to 'System/Posix/Temp.hsc')
-rw-r--r--System/Posix/Temp.hsc23
1 files changed, 19 insertions, 4 deletions
diff --git a/System/Posix/Temp.hsc b/System/Posix/Temp.hsc
index 26c6f65..6125802 100644
--- a/System/Posix/Temp.hsc
+++ b/System/Posix/Temp.hsc
@@ -32,6 +32,21 @@ import System.Posix.IO
import System.Posix.Types
import Foreign.C
+#if __GLASGOW_HASKELL__ > 700
+import System.Posix.Internals (withFilePath, peekFilePath)
+#elif __GLASGOW_HASKELL__ > 611
+import System.Posix.Internals (withFilePath)
+
+peekFilePath :: CString -> IO FilePath
+peekFilePath = peekCString
+#else
+withFilePath :: FilePath -> (CString -> IO a) -> IO a
+withFilePath = withCString
+
+peekFilePath :: CString -> IO FilePath
+peekFilePath = peekCString
+#endif
+
-- |'mkstemp' - make a unique filename and open it for
-- reading\/writing (only safe on GHC & Hugs).
-- The returned 'FilePath' is the (possibly relative) path of
@@ -39,9 +54,9 @@ import Foreign.C
mkstemp :: String -> IO (FilePath, Handle)
mkstemp template = do
#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
- withCString template $ \ ptr -> do
+ withFilePath template $ \ ptr -> do
fd <- throwErrnoIfMinus1 "mkstemp" (c_mkstemp ptr)
- name <- peekCString ptr
+ name <- peekFilePath ptr
h <- fdToHandle (Fd fd)
return (name, h)
#else
@@ -54,9 +69,9 @@ mkstemp template = do
mktemp :: String -> IO String
mktemp template = do
- withCString template $ \ ptr -> do
+ withFilePath template $ \ ptr -> do
ptr <- throwErrnoIfNull "mktemp" (c_mktemp ptr)
- peekCString ptr
+ peekFilePath ptr
foreign import ccall unsafe "mktemp"
c_mktemp :: CString -> IO CString