aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/Temp.hsc
diff options
context:
space:
mode:
authorGravatar stolz <unknown>2003-05-27 12:54:18 +0000
committerGravatar stolz <unknown>2003-05-27 12:54:18 +0000
commitbfd5af5903b39ff447c28e231b031dfd4b8e97a3 (patch)
tree3eea1a3af5e5a9c36a3291cbc71bde2ba56528b7 /System/Posix/Temp.hsc
parenta265cb8bb4e9b763b97d0dff9c7c449553390cd6 (diff)
[project @ 2003-05-27 12:54:18 by stolz]
Throw in mktemp() as well, as the non-GHC/Hugs case was essentially that. Advantage: At least on FreeBSD the linker will print out a warning whenever you use mktemp().
Diffstat (limited to 'System/Posix/Temp.hsc')
-rw-r--r--System/Posix/Temp.hsc28
1 files changed, 21 insertions, 7 deletions
diff --git a/System/Posix/Temp.hsc b/System/Posix/Temp.hsc
index eef5e34..bb5b987 100644
--- a/System/Posix/Temp.hsc
+++ b/System/Posix/Temp.hsc
@@ -15,10 +15,10 @@
module System.Posix.Temp (
- mkstemp
+ mktemp
+ , mkstemp
{- Not ported (yet?):
- mktemp: unsafe
tmpfile: can we handle FILE*?
tmpnam: ISO C, should go in base?
tempname: dito
@@ -33,20 +33,34 @@ import System.Posix.IO
import System.Posix.Types
import Foreign.C
--- |'mkstemp' - make a unique filename.
+-- |'mkstemp' - make a unique filename and open it for
+-- reading/writing (only safe on GHC & Hugs)
mkstemp :: String -> IO (String, Handle)
mkstemp template = do
+#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
withCString template $ \ ptr -> do
fd <- throwErrnoIfMinus1 "mkstemp" (c_mkstemp ptr)
name <- peekCString ptr
-#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
h <- fdToHandle fd
+ return (name, h)
#else
- closeFd fd
- h <- openFile name ReadWriteMode
+ name <- mktemp template
+ h <- openFile name ReadWriteMode
+ return (name, h)
#endif
- return (name, h)
+
+-- |'mktemp' - make a unique file name
+-- This function should be considered deprecated
+
+mktemp :: String -> IO String
+mktemp template = do
+ withCString template $ \ ptr -> do
+ ptr <- throwErrnoIfNull "mktemp" (c_mktemp ptr)
+ peekCString ptr
foreign import ccall unsafe "mkstemp"
c_mkstemp :: CString -> IO Fd
+
+foreign import ccall unsafe "mktemp"
+ c_mktemp :: CString -> IO CString