diff options
author | stolz <unknown> | 2003-05-27 08:20:42 +0000 |
---|---|---|
committer | stolz <unknown> | 2003-05-27 08:20:42 +0000 |
commit | 7871e1b9e8483190baa3986d7c0b8a998438c5b9 (patch) | |
tree | 936f7e4d13a6e75628491b3a85c164dce9022cf0 /System/Posix/Temp.hsc | |
parent | 23b5be871f3b25be1c0cac4275a6d635b66c640c (diff) |
[project @ 2003-05-27 08:20:42 by stolz]
Add mkstemp() wrapper, including (unsafe) fallback for non-GHCs
(fdToHandle required).
Suggested by: Martin Sj?gren
Diffstat (limited to 'System/Posix/Temp.hsc')
-rw-r--r-- | System/Posix/Temp.hsc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/System/Posix/Temp.hsc b/System/Posix/Temp.hsc new file mode 100644 index 0000000..4b8b40f --- /dev/null +++ b/System/Posix/Temp.hsc @@ -0,0 +1,51 @@ +{-# OPTIONS -fffi #-} +----------------------------------------------------------------------------- +-- | +-- Module : System.Posix.Temp +-- Copyright : (c) Volker Stolz <vs@foldr.org> +-- License : BSD-style (see the file libraries/base/LICENSE) +-- +-- Maintainer : vs@foldr.org +-- Stability : provisional +-- Portability : non-portable (requires POSIX) +-- +-- POSIX environment support +-- +----------------------------------------------------------------------------- + +module System.Posix.Temp ( + + mkstemp + +{- Not ported (yet?): + mktemp: unsafe + tmpfile: can we handle FILE*? + tmpnam: ISO C, should go in base? + tempname: dito +-} + +) where + +#include "HsUnix.h" + +import System.IO +import System.Posix.IO +import System.Posix.Types +import Foreign.C + +-- |'mkstemp' - make a unique filename. + +mkstemp :: String -> IO Handle +mkstemp template = do + withCString template $ \ ptr -> do + fd <- throwErrnoIfMinus1 "mkstemp" (c_mkstemp ptr) +#ifdef __GLASGOW_HASKELL__ + fdToHandle fd +#else + closeFd fd + name <- peekCString ptr + openFile name ReadWriteMode +#endif + +foreign import ccall unsafe "mkstemp" + c_mkstemp :: CString -> IO Fd |