{-# LINE 1 "System/Posix/Temp.hsc" #-}
{-# LINE 2 "System/Posix/Temp.hsc" #-}
{-# LANGUAGE Safe #-}
{-# LINE 6 "System/Posix/Temp.hsc" #-}
module System.Posix.Temp (
mkstemp, mkstemps, mkdtemp
) where
{-# LINE 26 "System/Posix/Temp.hsc" #-}
import Foreign.C
import System.IO
{-# LINE 32 "System/Posix/Temp.hsc" #-}
import System.Posix.IO
import System.Posix.Types
import System.Posix.Internals (withFilePath, peekFilePath)
{-# LINE 37 "System/Posix/Temp.hsc" #-}
foreign import ccall unsafe "HsUnix.h __hscore_mkstemp"
c_mkstemp :: CString -> IO CInt
{-# LINE 40 "System/Posix/Temp.hsc" #-}
mkstemp :: String -> IO (FilePath, Handle)
mkstemp template' = do
let template = template' ++ "XXXXXX"
{-# LINE 52 "System/Posix/Temp.hsc" #-}
withFilePath template $ \ ptr -> do
fd <- throwErrnoIfMinus1 "mkstemp" (c_mkstemp ptr)
name <- peekFilePath ptr
h <- fdToHandle (Fd fd)
return (name, h)
{-# LINE 62 "System/Posix/Temp.hsc" #-}
{-# LINE 64 "System/Posix/Temp.hsc" #-}
foreign import ccall unsafe "HsUnix.h __hscore_mkstemps"
c_mkstemps :: CString -> CInt -> IO CInt
{-# LINE 67 "System/Posix/Temp.hsc" #-}
mkstemps :: String -> String -> IO (FilePath, Handle)
{-# LINE 79 "System/Posix/Temp.hsc" #-}
mkstemps prefix suffix = do
let template = prefix ++ "XXXXXX" ++ suffix
lenOfsuf = (fromIntegral $ length suffix) :: CInt
withFilePath template $ \ ptr -> do
fd <- throwErrnoIfMinus1 "mkstemps" (c_mkstemps ptr lenOfsuf)
name <- peekFilePath ptr
h <- fdToHandle (Fd fd)
return (name, h)
{-# LINE 90 "System/Posix/Temp.hsc" #-}
{-# LINE 92 "System/Posix/Temp.hsc" #-}
foreign import ccall unsafe "HsUnix.h __hscore_mkdtemp"
c_mkdtemp :: CString -> IO CString
{-# LINE 95 "System/Posix/Temp.hsc" #-}
mkdtemp :: String -> IO FilePath
mkdtemp template' = do
let template = template' ++ "XXXXXX"
{-# LINE 107 "System/Posix/Temp.hsc" #-}
withFilePath template $ \ ptr -> do
_ <- throwErrnoIfNull "mkdtemp" (c_mkdtemp ptr)
name <- peekFilePath ptr
return name
{-# LINE 116 "System/Posix/Temp.hsc" #-}
{-# LINE 131 "System/Posix/Temp.hsc" #-}