aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/Temp.hsc
diff options
context:
space:
mode:
authorGravatar David Terei <davidterei@gmail.com>2012-01-05 18:50:00 -0800
committerGravatar David Terei <davidterei@gmail.com>2012-01-05 18:50:00 -0800
commit6d8b741f7ec6a72bdd6b76ca2a2509416be10b57 (patch)
tree4d8eeba71da12ba9e2abdd7beece52dbfaea5ce7 /System/Posix/Temp.hsc
parent1e963b41fb1f5b856aedd24587c879ad6b76bbb0 (diff)
Code clean and documentation improvements to Temp.
Diffstat (limited to 'System/Posix/Temp.hsc')
-rw-r--r--System/Posix/Temp.hsc48
1 files changed, 23 insertions, 25 deletions
diff --git a/System/Posix/Temp.hsc b/System/Posix/Temp.hsc
index 5308c1b..bfbfee1 100644
--- a/System/Posix/Temp.hsc
+++ b/System/Posix/Temp.hsc
@@ -8,26 +8,17 @@
-- Copyright : (c) Volker Stolz <vs@foldr.org>
-- License : BSD-style (see the file libraries/base/LICENSE)
--
--- Maintainer : vs@foldr.org
+-- Maintainer : libraries@haskell.org
-- Stability : provisional
-- Portability : non-portable (requires POSIX)
--
--- POSIX environment support
+-- POSIX temporary file and directory creation functions.
--
-----------------------------------------------------------------------------
module System.Posix.Temp (
-
- mkstemp
- , mkdtemp
-
-{- Not ported (yet?):
- tmpfile: can we handle FILE*?
- tmpnam: ISO C, should go in base?
- tempname: dito
--}
-
-) where
+ mkstemp, mkdtemp
+ ) where
#include "HsUnix.h"
@@ -39,11 +30,13 @@ 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
@@ -52,10 +45,13 @@ 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
--- the created file, which is padded with 6 random characters.
+-- | Make a unique filename and open it for reading\/writing. The returned
+-- 'FilePath' 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 :: String -> IO (FilePath, Handle)
mkstemp template' = do
let template = template' ++ "XXXXXX"
@@ -71,9 +67,12 @@ mkstemp template' = do
return (name, h)
#endif
--- |'mkdtemp' - make a unique directory (only safe on GHC & Hugs).
--- The returned 'FilePath' is the path of the created directory,
--- which is padded with 6 random characters.
+-- | Make a unique directory. The returned 'FilePath' 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 :: String -> IO FilePath
mkdtemp template' = do
let template = template' ++ "XXXXXX"
@@ -86,12 +85,10 @@ mkdtemp template' = do
name <- mktemp template
h <- createDirectory name (toEnum 0o700)
return name
-#endif
-#if !defined(__GLASGOW_HASKELL__) && !defined(__HUGS__)
--- |'mktemp' - make a unique file name
--- It is required that the template have six trailing \'X\'s.
--- This function should be considered deprecated
+-- | Make a unique file name It is required that the template have six trailing
+-- \'X\'s. This function should be considered deprecated.
+{-# WARNING mktemp "This function is unsafe; use mkstemp instead" #-}
mktemp :: String -> IO String
mktemp template = do
withFilePath template $ \ ptr -> do
@@ -107,3 +104,4 @@ foreign import ccall unsafe "HsUnix.h __hscore_mkstemp"
foreign import ccall unsafe "HsUnix.h __hscore_mkdtemp"
c_mkdtemp :: CString -> IO CString
+