aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/Temp.hsc
diff options
context:
space:
mode:
authorGravatar gwern0@gmail.com <unknown>2010-01-19 00:30:22 +0000
committerGravatar gwern0@gmail.com <unknown>2010-01-19 00:30:22 +0000
commite3c438d2da71380094e88f0de3c5471e29ac3d32 (patch)
tree8c79f0e98d60ba34e2dd498ee811783f4fbd36ac /System/Posix/Temp.hsc
parent93ed89887d5d762b06020ce6cd85ad7e7f9701d9 (diff)
System.Posix.Temp: pad input filenames with 6 Xs
If the argument doesn't terminate in capital Xs, the C mkstemp will simply bomb out with zero warning. This was not documented. By arbitrarily sticking a bunch of Xes at the end of all arguments, we guarantee that this exception will not be thrown, the type signature will not change, and no existing code can break (since if it was manually avoiding the exception by adding "XXX" itself, the temp files will now be simply 3 random characters longer, nothing worse).
Diffstat (limited to 'System/Posix/Temp.hsc')
-rw-r--r--System/Posix/Temp.hsc4
1 files changed, 2 insertions, 2 deletions
diff --git a/System/Posix/Temp.hsc b/System/Posix/Temp.hsc
index 824f917..8acfe59 100644
--- a/System/Posix/Temp.hsc
+++ b/System/Posix/Temp.hsc
@@ -35,7 +35,7 @@ import Foreign.C
-- |'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.
+-- the created file, which is padded with 6 random characters.
mkstemp :: String -> IO (FilePath, Handle)
mkstemp template = do
#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
@@ -45,7 +45,7 @@ mkstemp template = do
h <- fdToHandle (Fd fd)
return (name, h)
#else
- name <- mktemp template
+ name <- mktemp (template ++ "XXXXXX")
h <- openFile name ReadWriteMode
return (name, h)