{-# LINE 1 "System/Posix/Temp/ByteString.hsc" #-}{-# LANGUAGE CApiFFI #-}{-# LANGUAGE Safe #-}------------------------------------------------------------------------------- |-- Module : System.Posix.Temp.ByteString-- Copyright : (c) Volker Stolz <vs@foldr.org>-- Deian Stefan <deian@cs.stanford.edu>-- License : BSD-style (see the file libraries/base/LICENSE)---- Maintainer : libraries@haskell.org, vs@foldr.org, deian@cs.stanford.edu-- Stability : provisional-- Portability : non-portable (requires POSIX)---- POSIX temporary file and directory creation functions.-------------------------------------------------------------------------------moduleSystem.Posix.Temp.ByteString(mkstemp ,mkstemps ,mkdtemp )whereimportData.ByteString(ByteString)importqualifiedData.ByteStringasBimportqualifiedData.ByteString.Char8asBCimportForeign.CimportSystem.IOimportSystem.Posix.ByteString.FilePath {-# LINE 35 "System/Posix/Temp/ByteString.hsc" #-}importSystem.Posix.IO importSystem.Posix.Types{-# LINE 42 "System/Posix/Temp/ByteString.hsc" #-}{-# LINE 50 "System/Posix/Temp/ByteString.hsc" #-}foreignimportcapiunsafe"HsUnix.h mkstemp"c_mkstemp ::CString->IOCInt-- | Make a unique filename and open it for reading\/writing. The returned-- 'RawFilePath' is the (possibly relative) path of the created file, which is-- padded with 6 random characters. The argument is the desired prefix of the-- filepath of the temporary file to be created.---- If you aren't using GHC or Hugs then this function simply wraps mktemp and-- so shouldn't be considered safe.mkstemp ::ByteString->IO(RawFilePath ,Handle)mkstemp :: ByteString -> IO (ByteString, Handle)
mkstemp ByteString
template' =dolettemplate :: ByteString
template =ByteString
template' ByteString -> ByteString -> ByteString
`B.append`(String -> ByteString
BC.packString
"XXXXXX")ByteString
-> (CString -> IO (ByteString, Handle)) -> IO (ByteString, Handle)
forall a. ByteString -> (CString -> IO a) -> IO a
withFilePath ByteString
template ((CString -> IO (ByteString, Handle)) -> IO (ByteString, Handle))
-> (CString -> IO (ByteString, Handle)) -> IO (ByteString, Handle)
forall a b. (a -> b) -> a -> b
$\CString
ptr ->doCInt
fd <-String -> IO CInt -> IO CInt
forall a. (Eq a, Num a) => String -> IO a -> IO a
throwErrnoIfMinus1String
"mkstemp"(CString -> IO CInt
c_mkstemp CString
ptr )ByteString
name <-CString -> IO ByteString
peekFilePath CString
ptr Handle
h <-Fd -> IO Handle
fdToHandle (CInt -> Fd
FdCInt
fd )(ByteString, Handle) -> IO (ByteString, Handle)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return(ByteString
name ,Handle
h ){-# LINE 71 "System/Posix/Temp/ByteString.hsc" #-}{-# LINE 73 "System/Posix/Temp/ByteString.hsc" #-}foreignimportcapiunsafe"HsUnix.h mkstemps"c_mkstemps::CString->CInt->IOCInt{-# LINE 76 "System/Posix/Temp/ByteString.hsc" #-}-- |'mkstemps' - make a unique filename with a given prefix and suffix-- and open it for reading\/writing (only safe on GHC & Hugs).-- The returned 'RawFilePath' is the (possibly relative) path of-- the created file, which contains 6 random characters in between-- the prefix and suffix.mkstemps ::ByteString->ByteString->IO(RawFilePath ,Handle)mkstemps :: ByteString -> ByteString -> IO (ByteString, Handle)
{-# LINE 84 "System/Posix/Temp/ByteString.hsc" #-} mkstempsprefixsuffix=dolettemplate=prefix`B.append`(BC.pack"XXXXXX")`B.append`suffixlenOfsuf=(fromIntegral$B.lengthsuffix)::CIntwithFilePathtemplate$\ptr->dofd<-throwErrnoIfMinus1"mkstemps"(c_mkstempsptrlenOfsuf)name<-peekFilePathptrh<-fdToHandle(Fdfd)return(name,h){-# LINE 96 "System/Posix/Temp/ByteString.hsc" #-}{-# LINE 98 "System/Posix/Temp/ByteString.hsc" #-}foreignimportcapiunsafe"HsUnix.h mkdtemp"c_mkdtemp::CString->IOCString{-# LINE 101 "System/Posix/Temp/ByteString.hsc" #-}-- | Make a unique directory. The returned 'RawFilePath' is the path of the-- created directory, which is padded with 6 random characters. The argument is-- the desired prefix of the filepath of the temporary directory to be created.---- If you aren't using GHC or Hugs then this function simply wraps mktemp and-- so shouldn't be considered safe.mkdtemp ::ByteString->IORawFilePath mkdtemp :: ByteString -> IO ByteString
mkdtemp ByteString
template' =dolettemplate :: ByteString
template =ByteString
template' ByteString -> ByteString -> ByteString
`B.append`(String -> ByteString
BC.packString
"XXXXXX"){-# LINE 112 "System/Posix/Temp/ByteString.hsc" #-}withFilePathtemplate$\ptr->do_<-throwErrnoIfNull"mkdtemp"(c_mkdtempptr)name<-peekFilePathptrreturnname{-# LINE 121 "System/Posix/Temp/ByteString.hsc" #-}{-# LINE 136 "System/Posix/Temp/ByteString.hsc" #-}

AltStyle によって変換されたページ (->オリジナル) /