diff options
Diffstat (limited to 'libraries/base/System/IO.hs')
-rw-r--r-- | libraries/base/System/IO.hs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/libraries/base/System/IO.hs b/libraries/base/System/IO.hs index 04e976a85b..656f852a19 100644 --- a/libraries/base/System/IO.hs +++ b/libraries/base/System/IO.hs @@ -233,6 +233,8 @@ import System.Posix.Types import GHC.Base import GHC.List +import GHC.IORef +import GHC.Num import GHC.IO hiding ( bracket, onException ) import GHC.IO.IOMode import GHC.IO.Handle.FD @@ -508,15 +510,16 @@ openTempFile' loc tmp_dir template binary mode = findTempName | last a == pathSeparator = a ++ b | otherwise = a ++ [pathSeparator] ++ b --- int rand(void) from <stdlib.h>, limited by RAND_MAX (small value, 32768) -foreign import capi "stdlib.h rand" c_rand :: IO CInt +tempCounter :: IORef Int +tempCounter = unsafePerformIO $ newIORef 0 +{-# NOINLINE tempCounter #-} -- build large digit-alike number rand_string :: IO String rand_string = do - r1 <- c_rand - r2 <- c_rand - return $ show r1 ++ show r2 + r1 <- c_getpid + r2 <- atomicModifyIORef tempCounter (\n -> (n+1, n)) + return $ show r1 ++ "-" ++ show r2 data OpenNewFileResult = NewFileCreated CInt |