diff --git a/System/Posix/ByteString/FilePath.hsc b/System/Posix/ByteString/FilePath.hsc
--- a/System/Posix/ByteString/FilePath.hsc
+++ b/System/Posix/ByteString/FilePath.hsc
@@ -29,7 +29,7 @@
      throwErrnoPathIfMinus1_
   ) where
 
-import Foreign
+import Foreign hiding ( void )
 import Foreign.C hiding (
      throwErrnoPath,
      throwErrnoPathIf,
@@ -38,6 +38,7 @@
      throwErrnoPathIfMinus1,
      throwErrnoPathIfMinus1_ )
 
+import Control.Monad
 import Data.ByteString
 import Data.ByteString.Char8 as BC
 import Prelude hiding (FilePath)
diff --git a/System/Posix/Env.hsc b/System/Posix/Env.hsc
--- a/System/Posix/Env.hsc
+++ b/System/Posix/Env.hsc
@@ -17,25 +17,27 @@
 -----------------------------------------------------------------------------
 
 module System.Posix.Env (
-	getEnv
-	, getEnvDefault
-	, getEnvironmentPrim
-	, getEnvironment
-	, putEnv
-	, setEnv
-	, unsetEnv
+      getEnv
+    , getEnvDefault
+    , getEnvironmentPrim
+    , getEnvironment
+    , setEnvironment
+    , putEnv
+    , setEnv
+    , unsetEnv
+    , clearEnv
 ) where
 
 #include "HsUnix.h"
 
-import Foreign.C.Error	( throwErrnoIfMinus1_ )
+import Foreign.C.Error (throwErrnoIfMinus1_)
 import Foreign.C.Types
 import Foreign.C.String
 import Foreign.Marshal.Array
 import Foreign.Ptr
 import Foreign.Storable
-import Control.Monad	( liftM )
-import Data.Maybe	( fromMaybe )
+import Control.Monad
+import Data.Maybe (fromMaybe)
 #if __GLASGOW_HASKELL__ > 700
 import System.Posix.Internals (withFilePath, peekFilePath)
 #elif __GLASGOW_HASKELL__ > 611
@@ -73,10 +75,15 @@
 getEnvironmentPrim :: IO [String]
 getEnvironmentPrim = do
   c_environ <- getCEnviron
-  arr <- peekArray0 nullPtr c_environ
-  mapM peekFilePath arr
+  -- environ can be NULL
+  if c_environ == nullPtr
+    then return []
+    else do
+      arr <- peekArray0 nullPtr c_environ
+      mapM peekFilePath arr
 
 getCEnviron :: IO (Ptr CString)
+
 #if darwin_HOST_OS
 -- You should not access _environ directly on Darwin in a bundle/shared library.
 -- See #2458 and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html
@@ -102,6 +109,15 @@
    dropEq (x,'=':ys) = (x,ys)
    dropEq (x,_)      = error $ "getEnvironment: insane variable " ++ x
 
+-- |'setEnvironment' resets the entire environment to the given list of
+-- @(key,value)@ pairs.
+
+setEnvironment :: [(String,String)] -> IO ()
+setEnvironment env = do
+  clearEnv
+  forM_ env $ \(key,value) ->
+    setEnv key value True {-overwrite-}
+
 -- |The 'unsetEnv' function deletes all instances of the variable name
 -- from the environment.
 
@@ -140,7 +156,7 @@
   withFilePath key $ \ keyP ->
     withFilePath value $ \ valueP ->
       throwErrnoIfMinus1_ "setenv" $
-	c_setenv keyP valueP (fromIntegral (fromEnum ovrwrt))
+        c_setenv keyP valueP (fromIntegral (fromEnum ovrwrt))
 
 foreign import ccall unsafe "setenv"
    c_setenv :: CString -> CString -> CInt -> IO CInt
@@ -151,4 +167,19 @@
   case res of
     Just _  -> return ()
     Nothing -> putEnv (key++"="++value)
+#endif
+
+-- |The 'clearEnv' function clears the environment of all name-value pairs.
+clearEnv :: IO ()
+#if HAVE_CLEARENV
+clearEnv = void c_clearenv
+
+foreign import ccall unsafe "clearenv"
+  c_clearenv :: IO Int
+#else
+-- Fallback to 'environ[0] = NULL'.
+clearEnv = do
+  c_environ <- getCEnviron
+  unless (c_environ == nullPtr) $
+    poke c_environ nullPtr
 #endif
diff --git a/System/Posix/Error.hs b/System/Posix/Error.hs
--- a/System/Posix/Error.hs
+++ b/System/Posix/Error.hs
@@ -28,8 +28,9 @@
         throwErrnoPathIfMinus1Retry_
   ) where
 
-import Foreign
+import Foreign hiding (void)
 import Foreign.C
+import Control.Monad
 
 throwErrnoPathIfMinus1Retry :: (Eq a, Num a)
                             => String -> FilePath -> IO a -> IO a
diff --git a/System/Posix/Files.hsc b/System/Posix/Files.hsc
--- a/System/Posix/Files.hsc
+++ b/System/Posix/Files.hsc
@@ -57,6 +57,7 @@
     deviceID, fileID, fileMode, linkCount, fileOwner, fileGroup,
     specialDeviceID, fileSize, accessTime, modificationTime,
     statusChangeTime,
+    accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
     isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,
     isDirectory, isSymbolicLink, isSocket,
 
diff --git a/System/Posix/Files/ByteString.hsc b/System/Posix/Files/ByteString.hsc
--- a/System/Posix/Files/ByteString.hsc
+++ b/System/Posix/Files/ByteString.hsc
@@ -55,6 +55,7 @@
     deviceID, fileID, fileMode, linkCount, fileOwner, fileGroup,
     specialDeviceID, fileSize, accessTime, modificationTime,
     statusChangeTime,
+    accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
     isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,
     isDirectory, isSymbolicLink, isSocket,
 
diff --git a/System/Posix/Files/Common.hsc b/System/Posix/Files/Common.hsc
--- a/System/Posix/Files/Common.hsc
+++ b/System/Posix/Files/Common.hsc
@@ -54,6 +54,7 @@
     deviceID, fileID, fileMode, linkCount, fileOwner, fileGroup,
     specialDeviceID, fileSize, accessTime, modificationTime,
     statusChangeTime,
+    accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
     isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,
     isDirectory, isSymbolicLink, isSocket,
 
@@ -71,6 +72,8 @@
 import System.Posix.Types
 import System.IO.Unsafe
 import Data.Bits
+import Data.Time.Clock.POSIX
+import Data.Ratio
 import System.Posix.Internals
 import Foreign hiding (unsafePerformIO)
 import Foreign.C
@@ -233,10 +236,16 @@
 fileSize         :: FileStatus -> FileOffset
 -- | Time of last access.
 accessTime       :: FileStatus -> EpochTime
+-- | Time of last access in sub-second resolution.
+accessTimeHiRes  :: FileStatus -> POSIXTime
 -- | Time of last modification.
 modificationTime :: FileStatus -> EpochTime
+-- | Time of last modification in sub-second resolution.
+modificationTimeHiRes :: FileStatus -> POSIXTime
 -- | Time of last status change (i.e. owner, group, link count, mode, etc.).
 statusChangeTime :: FileStatus -> EpochTime
+-- | Time of last status change (i.e. owner, group, link count, mode, etc.) in sub-second resolution.
+statusChangeTimeHiRes :: FileStatus -> POSIXTime
 
 deviceID (FileStatus stat) = 
   unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_dev)
@@ -260,6 +269,75 @@
   unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_mtime)
 statusChangeTime (FileStatus stat) =
   unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_ctime)
+
+accessTimeHiRes (FileStatus stat) =
+  unsafePerformIO $ withForeignPtr stat $ \stat_ptr -> do
+    sec  <- (#peek struct stat, st_atime) stat_ptr :: IO EpochTime
+#ifdef HAVE_STRUCT_STAT_ST_ATIM
+    nsec <- (#peek struct stat, st_atim.tv_nsec) stat_ptr :: IO (#type long)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_ATIMESPEC
+    nsec <- (#peek struct stat, st_atimespec.tv_nsec) stat_ptr :: IO (#type long)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_ATIMENSEC
+    nsec <- (#peek struct stat, st_atimensec) stat_ptr :: IO (#type long)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_ATIME_N
+    nsec <- (#peek struct stat, st_atime_n) stat_ptr :: IO (#type int)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_UATIME
+    usec <- (#peek struct stat, st_uatime) stat_ptr :: IO (#type int)
+    let frac = toInteger usec % 10^(6::Int)
+#else
+    let frac = 0
+#endif
+    return $ fromRational $ toRational sec + frac
+
+modificationTimeHiRes (FileStatus stat) =
+  unsafePerformIO $ withForeignPtr stat $ \stat_ptr -> do
+    sec  <- (#peek struct stat, st_mtime) stat_ptr :: IO EpochTime
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+    nsec <- (#peek struct stat, st_mtim.tv_nsec) stat_ptr :: IO (#type long)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_MTIMESPEC
+    nsec <- (#peek struct stat, st_mtimespec.tv_nsec) stat_ptr :: IO (#type long)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_MTIMENSEC
+    nsec <- (#peek struct stat, st_mtimensec) stat_ptr :: IO (#type long)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_MTIME_N
+    nsec <- (#peek struct stat, st_mtime_n) stat_ptr :: IO (#type int)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_UMTIME
+    usec <- (#peek struct stat, st_umtime) stat_ptr :: IO (#type int)
+    let frac = toInteger usec % 10^(6::Int)
+#else
+    let frac = 0
+#endif
+    return $ fromRational $ toRational sec + frac
+
+statusChangeTimeHiRes (FileStatus stat) =
+  unsafePerformIO $ withForeignPtr stat $ \stat_ptr -> do
+    sec  <- (#peek struct stat, st_ctime) stat_ptr :: IO EpochTime
+#ifdef HAVE_STRUCT_STAT_ST_CTIM
+    nsec <- (#peek struct stat, st_ctim.tv_nsec) stat_ptr :: IO (#type long)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_CTIMESPEC
+    nsec <- (#peek struct stat, st_ctimespec.tv_nsec) stat_ptr :: IO (#type long)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_CTIMENSEC
+    nsec <- (#peek struct stat, st_ctimensec) stat_ptr :: IO (#type long)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_CTIME_N
+    nsec <- (#peek struct stat, st_ctime_n) stat_ptr :: IO (#type int)
+    let frac = toInteger nsec % 10^(9::Int)
+#elif HAVE_STRUCT_STAT_ST_UCTIME
+    usec <- (#peek struct stat, st_uctime) stat_ptr :: IO (#type int)
+    let frac = toInteger usec % 10^(6::Int)
+#else
+    let frac = 0
+#endif
+    return $ fromRational $ toRational sec + frac
 
 -- | Checks if this file is a block device.
 isBlockDevice     :: FileStatus -> Bool
diff --git a/System/Posix/Signals.hsc b/System/Posix/Signals.hsc
--- a/System/Posix/Signals.hsc
+++ b/System/Posix/Signals.hsc
@@ -612,13 +612,13 @@
 foreign import ccall unsafe "sigismember"
   c_sigismember :: Ptr CSigset -> CInt -> IO CInt
 #else
-foreign import ccall unsafe "__hscore_sigdelset"
+foreign import capi unsafe "signal.h sigdelset"
   c_sigdelset   :: Ptr CSigset -> CInt -> IO CInt
 
-foreign import ccall unsafe "__hscore_sigfillset"
+foreign import capi unsafe "signal.h sigfillset"
   c_sigfillset  :: Ptr CSigset -> IO CInt
 
-foreign import ccall unsafe "__hscore_sigismember"
+foreign import capi unsafe "signal.h sigismember"
   c_sigismember :: Ptr CSigset -> CInt -> IO CInt
 #endif /* __HUGS__ */
 
diff --git a/System/Posix/Temp.hsc b/System/Posix/Temp.hsc
--- a/System/Posix/Temp.hsc
+++ b/System/Posix/Temp.hsc
@@ -6,42 +6,40 @@
 -- |
 -- Module      :  System.Posix.Temp
 -- Copyright   :  (c) Volker Stolz <vs@foldr.org>
+--                    Deian Stefan <deian@cs.stanford.edu>
 -- License     :  BSD-style (see the file libraries/base/LICENSE)
 --
--- Maintainer  :  vs@foldr.org
+-- Maintainer  :  libraries@haskell.org, vs@foldr.org, deian@cs.stanford.edu
 -- Stability   :  provisional
 -- Portability :  non-portable (requires POSIX)
 --
--- POSIX environment support
+-- POSIX temporary file and directory creation functions.
 --
 -----------------------------------------------------------------------------
 
 module System.Posix.Temp (
-
-    mkstemp
-
-{- Not ported (yet?):
-    tmpfile: can we handle FILE*?
-    tmpnam: ISO C, should go in base?
-    tempname: dito
--}
-
-) where
+        mkstemp, mkstemps, mkdtemp
+    ) where
 
 #include "HsUnix.h"
 
+import Foreign.C
 import System.IO
+#if !HAVE_MKDTEMP
+import System.Posix.Directory (createDirectory)
+#endif
 import System.Posix.IO
 import System.Posix.Types
-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
@@ -50,12 +48,21 @@
 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.
+#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
+foreign import ccall unsafe "HsUnix.h __hscore_mkstemp"
+  c_mkstemp :: CString -> IO CInt
+#endif
+
+-- | 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
+mkstemp template' = do
+  let template = template' ++ "XXXXXX"
 #if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
   withFilePath template $ \ ptr -> do
     fd <- throwErrnoIfMinus1 "mkstemp" (c_mkstemp ptr)
@@ -63,23 +70,77 @@
     h <- fdToHandle (Fd fd)
     return (name, h)
 #else
-  name <- mktemp (template ++ "XXXXXX")
+  name <- mktemp template
   h <- openFile name ReadWriteMode
   return (name, h)
+#endif
 
--- |'mktemp' - make a unique file name
--- This function should be considered deprecated
+#if HAVE_MKSTEMPS
+foreign import ccall unsafe "HsUnix.h __hscore_mkstemps"
+  c_mkstemps :: CString -> CInt -> IO CInt
+#endif
 
+-- | Make a unique filename with a given prefix and suffix and open it for
+-- reading\/writing. The returned 'FilePath' is the (possibly relative) path of
+-- the created file, which contains  6 random characters in between the prefix
+-- and suffix. The first argument is the desired prefix of the filepath of the
+-- temporary file to be created. The second argument is the suffix of the
+-- temporary file to be created.
+--
+-- If you are using as system that doesn't support the mkstemps glibc function
+-- (supported in glibc > 2.11) then this function simply throws an error.
+mkstemps :: String -> String -> IO (FilePath, Handle)
+#if HAVE_MKSTEMPS
+mkstemps prefix suffix = do
+  let template = prefix ++ "XXXXXX" ++ suffix
+      lenOfsuf = (fromIntegral $ length suffix) :: CInt
+  withFilePath template $ \ ptr -> do
+    fd <- throwErrnoIfMinus1 "mkstemps" (c_mkstemps ptr lenOfsuf)
+    name <- peekFilePath ptr
+    h <- fdToHandle (Fd fd)
+    return (name, h)
+#else
+mkstemps = error "System.Posix.Temp.mkstemps: not available on this platform" 
+#endif
+
+#if HAVE_MKDTEMP
+foreign import ccall unsafe "HsUnix.h __hscore_mkdtemp"
+  c_mkdtemp :: CString -> IO CString
+#endif
+
+-- | 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 are using as system that doesn't support the mkdtemp glibc function
+-- (supported in glibc > 2.1.91) then this function uses mktemp and so
+-- shouldn't be considered safe.
+mkdtemp :: String -> IO FilePath
+mkdtemp template' = do
+  let template = template' ++ "XXXXXX"
+#if HAVE_MKDTEMP
+  withFilePath template $ \ ptr -> do
+    _ <- throwErrnoIfNull "mkdtemp" (c_mkdtemp ptr)
+    name <- peekFilePath ptr
+    return name
+#else
+  name <- mktemp template
+  h <- createDirectory name (toEnum 0o700)
+  return name
+#endif
+
+#if (!defined(__GLASGOW_HASKELL__) && !defined(__HUGS__)) || !HAVE_MKDTEMP
+
+foreign import ccall unsafe "mktemp"
+  c_mktemp :: CString -> IO CString
+
+-- | 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
     ptr <- throwErrnoIfNull "mktemp" (c_mktemp ptr)
     peekFilePath ptr
-
-foreign import ccall unsafe "mktemp"
-  c_mktemp :: CString -> IO CString
 #endif
-
-foreign import ccall unsafe "HsUnix.h __hscore_mkstemp"
-  c_mkstemp :: CString -> IO CInt
 
diff --git a/System/Posix/Temp/ByteString.hsc b/System/Posix/Temp/ByteString.hsc
--- a/System/Posix/Temp/ByteString.hsc
+++ b/System/Posix/Temp/ByteString.hsc
@@ -6,53 +6,52 @@
 -- |
 -- Module      :  System.Posix.Temp.ByteString
 -- Copyright   :  (c) Volker Stolz <vs@foldr.org>
+--                    Deian Stefan <deian@cs.stanford.edu>
 -- License     :  BSD-style (see the file libraries/base/LICENSE)
 --
--- Maintainer  :  vs@foldr.org
+-- Maintainer  :  libraries@haskell.org, vs@foldr.org, deian@cs.stanford.edu
 -- Stability   :  provisional
 -- Portability :  non-portable (requires POSIX)
 --
--- POSIX environment support
+-- POSIX temporary file and directory creation functions.
 --
 -----------------------------------------------------------------------------
 
 module System.Posix.Temp.ByteString (
-
-    mkstemp
-
-{- Not ported (yet?):
-    tmpfile: can we handle FILE*?
-    tmpnam: ISO C, should go in base?
-    tempname: dito
--}
-
-) where
+        mkstemp, mkstemps, mkdtemp
+    ) where
 
 #include "HsUnix.h"
 
-import System.IO        (Handle)
-import System.Posix.IO
-import System.Posix.Types
+import Data.ByteString (ByteString)
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Char8 as BC
 
-import Foreign.C hiding (
-     throwErrnoPath,
-     throwErrnoPathIf,
-     throwErrnoPathIf_,
-     throwErrnoPathIfNull,
-     throwErrnoPathIfMinus1,
-     throwErrnoPathIfMinus1_ )
+import Foreign.C
 
+import System.IO
 import System.Posix.ByteString.FilePath
-
-import Data.ByteString (ByteString)
+#if !HAVE_MKDTEMP
+import System.Posix.Directory (createDirectory)
+#endif
+import System.Posix.IO
+import System.Posix.Types
 
+#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
+foreign import ccall unsafe "HsUnix.h __hscore_mkstemp"
+  c_mkstemp :: CString -> IO CInt
+#endif
 
--- |'mkstemp' - make a unique filename and open it for
--- reading\/writing (only safe on GHC & Hugs).
--- The returned 'RawFilePath' 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
+-- 'RawFilePath' 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 :: ByteString -> IO (RawFilePath, Handle)
-mkstemp template = do
+mkstemp template' = do
+  let template = template' `B.append` (BC.pack "XXXXXX")
 #if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
   withFilePath template $ \ ptr -> do
     fd <- throwErrnoIfMinus1 "mkstemp" (c_mkstemp ptr)
@@ -60,23 +59,72 @@
     h <- fdToHandle (Fd fd)
     return (name, h)
 #else
-  name <- mktemp (template ++ "XXXXXX")
-  h <- openFile name ReadWriteMode
+  name <- mktemp template
+  h <- openFile (BC.unpack name) ReadWriteMode
   return (name, h)
+#endif
 
--- |'mktemp' - make a unique file name
--- This function should be considered deprecated
+#if HAVE_MKSTEMPS
+foreign import ccall unsafe "HsUnix.h __hscore_mkstemps"
+  c_mkstemps :: CString -> CInt -> IO CInt
+#endif
 
+-- |'mkstemps' - make a unique filename with a given prefix and suffix 
+-- and open it for reading\/writing (only safe on GHC & Hugs).
+-- The returned 'RawFilePath' is the (possibly relative) path of
+-- the created file, which contains  6 random characters in between
+-- the prefix and suffix.
+mkstemps :: ByteString -> ByteString -> IO (RawFilePath, Handle)
+#if HAVE_MKSTEMPS
+mkstemps prefix suffix = do
+  let template = prefix `B.append` (BC.pack "XXXXXX") `B.append` suffix
+      lenOfsuf = (fromIntegral $ B.length suffix) :: CInt
+  withFilePath template $ \ ptr -> do
+    fd <- throwErrnoIfMinus1 "mkstemps" (c_mkstemps ptr lenOfsuf)
+    name <- peekFilePath ptr
+    h <- fdToHandle (Fd fd)
+    return (name, h)
+#else
+mkstemps = error "System.Posix.Temp.mkstemps: not available on this platform" 
+#endif
+
+#if HAVE_MKDTEMP
+foreign import ccall unsafe "HsUnix.h __hscore_mkdtemp"
+  c_mkdtemp :: CString -> IO CString
+#endif
+
+-- | Make a unique directory. The returned 'RawFilePath' 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 :: ByteString -> IO RawFilePath
+mkdtemp template' = do
+  let template = template' `B.append` (BC.pack "XXXXXX")
+#if HAVE_MKDTEMP
+  withFilePath template $ \ ptr -> do
+    _ <- throwErrnoIfNull "mkdtemp" (c_mkdtemp ptr)
+    name <- peekFilePath ptr
+    return name
+#else
+  name <- mktemp template
+  h <- createDirectory (BC.unpack name) (toEnum 0o700)
+  return name
+#endif
+
+#if (!defined(__GLASGOW_HASKELL__) && !defined(__HUGS__)) || !HAVE_MKDTEMP
+
+foreign import ccall unsafe "mktemp"
+  c_mktemp :: CString -> IO CString
+
+-- | 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 :: ByteString -> IO RawFilePath
 mktemp template = do
   withFilePath template $ \ ptr -> do
     ptr <- throwErrnoIfNull "mktemp" (c_mktemp ptr)
     peekFilePath ptr
-
-foreign import ccall unsafe "mktemp"
-  c_mktemp :: CString -> IO CString
 #endif
-
-foreign import ccall unsafe "HsUnix.h __hscore_mkstemp"
-  c_mkstemp :: CString -> IO CInt
 
diff --git a/System/Posix/Unistd.hsc b/System/Posix/Unistd.hsc
--- a/System/Posix/Unistd.hsc
+++ b/System/Posix/Unistd.hsc
@@ -95,18 +95,28 @@
 -- | Sleep for the specified duration (in seconds).  Returns the time remaining
 -- (if the sleep was interrupted by a signal, for example).
 --
--- GHC Note: the comment for 'usleep' also applies here.
+-- /GHC Note/: 'Control.Concurrent.threadDelay' is a better choice.  Since GHC
+-- uses signals for its internal clock, a call to 'sleep' will usually be
+-- interrupted immediately.  That makes 'sleep' unusable in a program compiled
+-- with GHC, unless the RTS timer is disabled (with @+RTS -V0@).  Furthermore,
+-- without the @-threaded@ option, 'sleep' will block all other user threads.
+-- Even with the @-threaded@ option, 'sleep' requires a full OS thread to
+-- itself.  'Control.Concurrent.threadDelay' has none of these shortcomings.
 --
 sleep :: Int -> IO Int
 sleep 0 = return 0
 sleep secs = do r <- c_sleep (fromIntegral secs); return (fromIntegral r)
 
+#ifdef __GLASGOW_HASKELL__
+{-# WARNING sleep "This function has several shortcomings (see documentation). Please consider using Control.Concurrent.threadDelay instead." #-}
+#endif
+
 foreign import ccall safe "sleep"
   c_sleep :: CUInt -> IO CUInt
 
 -- | Sleep for the specified duration (in microseconds).
 --
--- GHC Note: 'Control.Concurrent.threadDelay' is a better choice.
+-- /GHC Note/: 'Control.Concurrent.threadDelay' is a better choice.
 -- Without the @-threaded@ option, 'usleep' will block all other user
 -- threads.  Even with the @-threaded@ option, 'usleep' requires a
 -- full OS thread to itself.  'Control.Concurrent.threadDelay' has
@@ -134,6 +144,7 @@
 
 -- | Sleep for the specified duration (in nanoseconds)
 --
+-- /GHC Note/: the comment for 'usleep' also applies here.
 nanosleep :: Integer -> IO ()
 #ifndef HAVE_NANOSLEEP
 nanosleep = error "nanosleep: not available on this platform"
diff --git a/cbits/HsUnix.c b/cbits/HsUnix.c
--- a/cbits/HsUnix.c
+++ b/cbits/HsUnix.c
@@ -134,6 +134,19 @@
 }
 #endif
 
+#if HAVE_MKSTEMPS
+int __hscore_mkstemps(char *filetemplate, int suffixlen) {
+    return (mkstemps(filetemplate, suffixlen));
+}
+#endif
+
+#if HAVE_MKDTEMP
+char *__hscore_mkdtemp(char *filetemplate) {
+    return (mkdtemp(filetemplate));
+}
+#endif
+
+
 #if !defined(__MINGW32__) && !defined(irix_HOST_OS)
 int __hscore_getrlimit(int resource, struct rlimit *rlim) {
     return (getrlimit(resource, rlim));
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for Haskell unix package 2.0.
+# Generated by GNU Autoconf 2.67 for Haskell unix package 2.0.
 #
 # Report bugs to <libraries@haskell.org>.
 #
@@ -91,7 +91,6 @@
 IFS=" ""	$as_nl"
 
 # Find who we are.  Look in the path if we contain no directory separator.
-as_myself=
 case $0 in #((
   *[\\/]* ) as_myself=$0 ;;
   *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -217,18 +216,11 @@
   # We cannot yet assume a decent shell, so we have to provide a
 	# neutralization value for shells without unset; and this also
 	# works around shells that cannot unset nonexistent variables.
-	# Preserve -v and -x to the replacement shell.
 	BASH_ENV=/dev/null
 	ENV=/dev/null
 	(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
 	export CONFIG_SHELL
-	case $- in # ((((
-	  *v*x* | *x*v* ) as_opts=-vx ;;
-	  *v* ) as_opts=-v ;;
-	  *x* ) as_opts=-x ;;
-	  * ) as_opts= ;;
-	esac
-	exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"}
+	exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
 fi
 
     if test x$as_have_required = xno; then :
@@ -1085,7 +1077,7 @@
     $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
     expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
       $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
-    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
+    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
     ;;
 
   esac
@@ -1381,7 +1373,7 @@
 if $ac_init_version; then
   cat <<\_ACEOF
 Haskell unix package configure 2.0
-generated by GNU Autoconf 2.68
+generated by GNU Autoconf 2.67
 
 Copyright (C) 2010 Free Software Foundation, Inc.
 This configure script is free software; the Free Software Foundation
@@ -1427,7 +1419,7 @@
 
 	ac_retval=1
 fi
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
   as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_compile
@@ -1464,7 +1456,7 @@
 
     ac_retval=1
 fi
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
   as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_cpp
@@ -1477,10 +1469,10 @@
 ac_fn_c_check_header_mongrel ()
 {
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  if eval \${$3+:} false; then :
+  if eval "test \"\${$3+set}\"" = set; then :
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval \${$3+:} false; then :
+if eval "test \"\${$3+set}\"" = set; then :
   $as_echo_n "(cached) " >&6
 fi
 eval ac_res=\$$3
@@ -1547,7 +1539,7 @@
 esac
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval \${$3+:} false; then :
+if eval "test \"\${$3+set}\"" = set; then :
   $as_echo_n "(cached) " >&6
 else
   eval "$3=\$ac_header_compiler"
@@ -1556,7 +1548,7 @@
 	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
 $as_echo "$ac_res" >&6; }
 fi
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
 
 } # ac_fn_c_check_header_mongrel
 
@@ -1597,7 +1589,7 @@
        ac_retval=$ac_status
 fi
   rm -rf conftest.dSYM conftest_ipa8_conftest.oo
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
   as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_run
@@ -1611,7 +1603,7 @@
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval \${$3+:} false; then :
+if eval "test \"\${$3+set}\"" = set; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -1629,7 +1621,7 @@
 eval ac_res=\$$3
 	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
 $as_echo "$ac_res" >&6; }
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
 
 } # ac_fn_c_check_header_compile
 
@@ -1674,7 +1666,7 @@
   # interfere with the next link command; also delete a directory that is
   # left behind by Apple's compiler.  We do this before executing the actions.
   rm -rf conftest.dSYM conftest_ipa8_conftest.oo
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
   as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_link
@@ -1687,7 +1679,7 @@
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval \${$3+:} false; then :
+if eval "test \"\${$3+set}\"" = set; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -1742,10 +1734,67 @@
 eval ac_res=\$$3
 	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
 $as_echo "$ac_res" >&6; }
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
 
 } # ac_fn_c_check_func
 
+# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
+# ----------------------------------------------------
+# Tries to find if the field MEMBER exists in type AGGR, after including
+# INCLUDES, setting cache variable VAR accordingly.
+ac_fn_c_check_member ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
+$as_echo_n "checking for $2.$3... " >&6; }
+if eval "test \"\${$4+set}\"" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$5
+int
+main ()
+{
+static $2 ac_aggr;
+if (ac_aggr.$3)
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$4=yes"
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$5
+int
+main ()
+{
+static $2 ac_aggr;
+if (sizeof ac_aggr.$3)
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$4=yes"
+else
+  eval "$4=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$4
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_member
+
 # ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
 # --------------------------------------------
 # Tries to find the compile-time value of EXPR in a program that includes
@@ -1919,7 +1968,7 @@
 rm -f conftest.val
 
   fi
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
   as_fn_set_status $ac_retval
 
 } # ac_fn_c_compute_int
@@ -1928,7 +1977,7 @@
 running configure, to aid debugging if configure makes a mistake.
 
 It was created by Haskell unix package $as_me 2.0, which was
-generated by GNU Autoconf 2.68.  Invocation command line was
+generated by GNU Autoconf 2.67.  Invocation command line was
 
   $ $0 $@
 
@@ -2186,7 +2235,7 @@
       || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "failed to load site script $ac_site_file
-See \`config.log' for more details" "$LINENO" 5; }
+See \`config.log' for more details" "$LINENO" 5 ; }
   fi
 done
 
@@ -2295,7 +2344,7 @@
 set dummy ${ac_tool_prefix}gcc; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -2335,7 +2384,7 @@
 set dummy gcc; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_CC+:} false; then :
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_CC"; then
@@ -2388,7 +2437,7 @@
 set dummy ${ac_tool_prefix}cc; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -2428,7 +2477,7 @@
 set dummy cc; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -2487,7 +2536,7 @@
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -2531,7 +2580,7 @@
 set dummy $ac_prog; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_CC+:} false; then :
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_CC"; then
@@ -2586,7 +2635,7 @@
 test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "no acceptable C compiler found in \$PATH
-See \`config.log' for more details" "$LINENO" 5; }
+See \`config.log' for more details" "$LINENO" 5 ; }
 
 # Provide some information about the compiler.
 $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
@@ -2701,7 +2750,7 @@
 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error 77 "C compiler cannot create executables
-See \`config.log' for more details" "$LINENO" 5; }
+See \`config.log' for more details" "$LINENO" 5 ; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
@@ -2744,7 +2793,7 @@
   { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "cannot compute suffix of executables: cannot compile and link
-See \`config.log' for more details" "$LINENO" 5; }
+See \`config.log' for more details" "$LINENO" 5 ; }
 fi
 rm -f conftest conftest$ac_cv_exeext
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
@@ -2803,7 +2852,7 @@
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "cannot run C compiled programs.
 If you meant to cross compile, use \`--host'.
-See \`config.log' for more details" "$LINENO" 5; }
+See \`config.log' for more details" "$LINENO" 5 ; }
     fi
   fi
 fi
@@ -2814,7 +2863,7 @@
 ac_clean_files=$ac_clean_files_save
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
 $as_echo_n "checking for suffix of object files... " >&6; }
-if ${ac_cv_objext+:} false; then :
+if test "${ac_cv_objext+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -2855,7 +2904,7 @@
 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "cannot compute suffix of object files: cannot compile
-See \`config.log' for more details" "$LINENO" 5; }
+See \`config.log' for more details" "$LINENO" 5 ; }
 fi
 rm -f conftest.$ac_cv_objext conftest.$ac_ext
 fi
@@ -2865,7 +2914,7 @@
 ac_objext=$OBJEXT
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
-if ${ac_cv_c_compiler_gnu+:} false; then :
+if test "${ac_cv_c_compiler_gnu+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -2902,7 +2951,7 @@
 ac_save_CFLAGS=$CFLAGS
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
 $as_echo_n "checking whether $CC accepts -g... " >&6; }
-if ${ac_cv_prog_cc_g+:} false; then :
+if test "${ac_cv_prog_cc_g+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_save_c_werror_flag=$ac_c_werror_flag
@@ -2980,7 +3029,7 @@
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
-if ${ac_cv_prog_cc_c89+:} false; then :
+if test "${ac_cv_prog_cc_c89+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_cv_prog_cc_c89=no
@@ -3093,7 +3142,7 @@
   CPP=
 fi
 if test -z "$CPP"; then
-  if ${ac_cv_prog_CPP+:} false; then :
+  if test "${ac_cv_prog_CPP+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
       # Double quotes because CPP needs to be expanded
@@ -3209,7 +3258,7 @@
   { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
-See \`config.log' for more details" "$LINENO" 5; }
+See \`config.log' for more details" "$LINENO" 5 ; }
 fi
 
 ac_ext=c
@@ -3221,7 +3270,7 @@
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
 $as_echo_n "checking for grep that handles long lines and -e... " >&6; }
-if ${ac_cv_path_GREP+:} false; then :
+if test "${ac_cv_path_GREP+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   if test -z "$GREP"; then
@@ -3284,7 +3333,7 @@
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
 $as_echo_n "checking for egrep... " >&6; }
-if ${ac_cv_path_EGREP+:} false; then :
+if test "${ac_cv_path_EGREP+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
@@ -3351,7 +3400,7 @@
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
 $as_echo_n "checking for ANSI C header files... " >&6; }
-if ${ac_cv_header_stdc+:} false; then :
+if test "${ac_cv_header_stdc+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -3479,7 +3528,7 @@
 
 
 ac_fn_c_check_header_mongrel "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default"
-if test "x$ac_cv_header_dlfcn_h" = xyes; then :
+if test "x$ac_cv_header_dlfcn_h" = x""yes; then :
   BUILD_PACKAGE_BOOL=True
 else
   BUILD_PACKAGE_BOOL=False
@@ -3490,7 +3539,7 @@
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5
 $as_echo_n "checking for an ANSI C-conforming const... " >&6; }
-if ${ac_cv_c_const+:} false; then :
+if test "${ac_cv_c_const+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -3578,7 +3627,7 @@
 
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for special C compiler options needed for large files" >&5
 $as_echo_n "checking for special C compiler options needed for large files... " >&6; }
-if ${ac_cv_sys_largefile_CC+:} false; then :
+if test "${ac_cv_sys_largefile_CC+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_cv_sys_largefile_CC=no
@@ -3629,7 +3678,7 @@
 
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _FILE_OFFSET_BITS value needed for large files" >&5
 $as_echo_n "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; }
-if ${ac_cv_sys_file_offset_bits+:} false; then :
+if test "${ac_cv_sys_file_offset_bits+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   while :; do
@@ -3698,7 +3747,7 @@
   if test $ac_cv_sys_file_offset_bits = unknown; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _LARGE_FILES value needed for large files" >&5
 $as_echo_n "checking for _LARGE_FILES value needed for large files... " >&6; }
-if ${ac_cv_sys_large_files+:} false; then :
+if test "${ac_cv_sys_large_files+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   while :; do
@@ -3858,7 +3907,7 @@
 fi
 done
 
-for ac_func in lchown setenv sysconf unsetenv
+for ac_func in lchown setenv sysconf unsetenv clearenv
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -3873,7 +3922,7 @@
 for ac_func in nanosleep
 do :
   ac_fn_c_check_func "$LINENO" "nanosleep" "ac_cv_func_nanosleep"
-if test "x$ac_cv_func_nanosleep" = xyes; then :
+if test "x$ac_cv_func_nanosleep" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_NANOSLEEP 1
 _ACEOF
@@ -3884,7 +3933,7 @@
 for ac_func in ptsname
 do :
   ac_fn_c_check_func "$LINENO" "ptsname" "ac_cv_func_ptsname"
-if test "x$ac_cv_func_ptsname" = xyes; then :
+if test "x$ac_cv_func_ptsname" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_PTSNAME 1
 _ACEOF
@@ -3895,7 +3944,7 @@
 for ac_func in setitimer
 do :
   ac_fn_c_check_func "$LINENO" "setitimer" "ac_cv_func_setitimer"
-if test "x$ac_cv_func_setitimer" = xyes; then :
+if test "x$ac_cv_func_setitimer" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_SETITIMER 1
 _ACEOF
@@ -3906,7 +3955,7 @@
 for ac_func in readdir_r
 do :
   ac_fn_c_check_func "$LINENO" "readdir_r" "ac_cv_func_readdir_r"
-if test "x$ac_cv_func_readdir_r" = xyes; then :
+if test "x$ac_cv_func_readdir_r" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_READDIR_R 1
 _ACEOF
@@ -3915,10 +3964,175 @@
 done
 
 
+ac_fn_c_check_member "$LINENO" "struct stat" "st_atim" "ac_cv_member_struct_stat_st_atim" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_atim" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_ATIM 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_mtim" "ac_cv_member_struct_stat_st_mtim" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_mtim" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_MTIM 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_ctim" "ac_cv_member_struct_stat_st_ctim" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_ctim" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_CTIM 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_atimespec" "ac_cv_member_struct_stat_st_atimespec" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_atimespec" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_ATIMESPEC 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_mtimespec" "ac_cv_member_struct_stat_st_mtimespec" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_mtimespec" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_MTIMESPEC 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_ctimespec" "ac_cv_member_struct_stat_st_ctimespec" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_ctimespec" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_CTIMESPEC 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_atimensec" "ac_cv_member_struct_stat_st_atimensec" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_atimensec" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_ATIMENSEC 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_mtimensec" "ac_cv_member_struct_stat_st_mtimensec" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_mtimensec" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_MTIMENSEC 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_ctimensec" "ac_cv_member_struct_stat_st_ctimensec" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_ctimensec" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_CTIMENSEC 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_atime_n" "ac_cv_member_struct_stat_st_atime_n" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_atime_n" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_ATIME_N 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_mtime_n" "ac_cv_member_struct_stat_st_mtime_n" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_mtime_n" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_MTIME_N 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_ctime_n" "ac_cv_member_struct_stat_st_ctime_n" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_ctime_n" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_CTIME_N 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_uatime" "ac_cv_member_struct_stat_st_uatime" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_uatime" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_UATIME 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_umtime" "ac_cv_member_struct_stat_st_umtime" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_umtime" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_UMTIME 1
+_ACEOF
+
+
+fi
+
+ac_fn_c_check_member "$LINENO" "struct stat" "st_uctime" "ac_cv_member_struct_stat_st_uctime" "$ac_includes_default"
+if test "x$ac_cv_member_struct_stat_st_uctime" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_STAT_ST_UCTIME 1
+_ACEOF
+
+
+fi
+
+
+# Additional temp functions
+for ac_func in mkstemps mkdtemp
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
 # Avoid adding rt if absent or unneeded
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shm_open in -lrt" >&5
 $as_echo_n "checking for shm_open in -lrt... " >&6; }
-if ${ac_cv_lib_rt_shm_open+:} false; then :
+if test "${ac_cv_lib_rt_shm_open+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
@@ -3952,7 +4166,7 @@
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_shm_open" >&5
 $as_echo "$ac_cv_lib_rt_shm_open" >&6; }
-if test "x$ac_cv_lib_rt_shm_open" = xyes; then :
+if test "x$ac_cv_lib_rt_shm_open" = x""yes; then :
   EXTRA_LIBS="$EXTRA_LIBS rt" CFLAGS="$CFLAGS -lrt"
 fi
 
@@ -3976,7 +4190,7 @@
 as_fp_Cache=`$as_echo "fp_cv_const_$fp_const_name" | $as_tr_sh`
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking value of $fp_const_name" >&5
 $as_echo_n "checking value of $fp_const_name... " >&6; }
-if eval \${$as_fp_Cache+:} false; then :
+if eval "test \"\${$as_fp_Cache+set}\"" = set; then :
   $as_echo_n "(cached) " >&6
 else
   if ac_fn_c_compute_int "$LINENO" "$fp_const_name" "fp_check_const_result"        "
@@ -4057,7 +4271,7 @@
 ### we'd like to return it; otherwise, we'll fake it.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking return type of usleep" >&5
 $as_echo_n "checking return type of usleep... " >&6; }
-if ${fptools_cv_func_usleep_return_type+:} false; then :
+if test "${fptools_cv_func_usleep_return_type+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -4088,7 +4302,7 @@
 ###  in common use return void.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking return type of unsetenv" >&5
 $as_echo_n "checking return type of unsetenv... " >&6; }
-if ${fptools_cv_func_unsetenv_return_type+:} false; then :
+if test "${fptools_cv_func_unsetenv_return_type+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -4263,7 +4477,7 @@
 for ac_func in openpty
 do :
   ac_fn_c_check_func "$LINENO" "openpty" "ac_cv_func_openpty"
-if test "x$ac_cv_func_openpty" = xyes; then :
+if test "x$ac_cv_func_openpty" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_OPENPTY 1
 _ACEOF
@@ -4271,7 +4485,7 @@
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for openpty in -lutil" >&5
 $as_echo_n "checking for openpty in -lutil... " >&6; }
-if ${ac_cv_lib_util_openpty+:} false; then :
+if test "${ac_cv_lib_util_openpty+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
@@ -4305,13 +4519,13 @@
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_util_openpty" >&5
 $as_echo "$ac_cv_lib_util_openpty" >&6; }
-if test "x$ac_cv_lib_util_openpty" = xyes; then :
+if test "x$ac_cv_lib_util_openpty" = x""yes; then :
   $as_echo "#define HAVE_OPENPTY 1" >>confdefs.h
  EXTRA_LIBS="$EXTRA_LIBS util"
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for openpty in -lbsd" >&5
 $as_echo_n "checking for openpty in -lbsd... " >&6; }
-if ${ac_cv_lib_bsd_openpty+:} false; then :
+if test "${ac_cv_lib_bsd_openpty+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
@@ -4345,7 +4559,7 @@
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bsd_openpty" >&5
 $as_echo "$ac_cv_lib_bsd_openpty" >&6; }
-if test "x$ac_cv_lib_bsd_openpty" = xyes; then :
+if test "x$ac_cv_lib_bsd_openpty" = x""yes; then :
   $as_echo "#define HAVE_OPENPTY 1" >>confdefs.h
  EXTRA_LIBS="$EXTRA_LIBS bsd"
 fi
@@ -4389,7 +4603,7 @@
 # Avoid adding dl if absent or unneeded
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
 $as_echo_n "checking for dlopen in -ldl... " >&6; }
-if ${ac_cv_lib_dl_dlopen+:} false; then :
+if test "${ac_cv_lib_dl_dlopen+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
@@ -4423,7 +4637,7 @@
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
 $as_echo "$ac_cv_lib_dl_dlopen" >&6; }
-if test "x$ac_cv_lib_dl_dlopen" = xyes; then :
+if test "x$ac_cv_lib_dl_dlopen" = x""yes; then :
   EXTRA_LIBS="$EXTRA_LIBS dl"
 fi
 
@@ -4465,7 +4679,7 @@
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
 $as_echo_n "checking build system type... " >&6; }
-if ${ac_cv_build+:} false; then :
+if test "${ac_cv_build+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_build_alias=$build_alias
@@ -4481,7 +4695,7 @@
 $as_echo "$ac_cv_build" >&6; }
 case $ac_cv_build in
 *-*-*) ;;
-*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;;
+*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5 ;;
 esac
 build=$ac_cv_build
 ac_save_IFS=$IFS; IFS='-'
@@ -4499,7 +4713,7 @@
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5
 $as_echo_n "checking host system type... " >&6; }
-if ${ac_cv_host+:} false; then :
+if test "${ac_cv_host+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   if test "x$host_alias" = x; then
@@ -4514,7 +4728,7 @@
 $as_echo "$ac_cv_host" >&6; }
 case $ac_cv_host in
 *-*-*) ;;
-*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;;
+*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5 ;;
 esac
 host=$ac_cv_host
 ac_save_IFS=$IFS; IFS='-'
@@ -4532,7 +4746,7 @@
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5
 $as_echo_n "checking target system type... " >&6; }
-if ${ac_cv_target+:} false; then :
+if test "${ac_cv_target+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   if test "x$target_alias" = x; then
@@ -4547,7 +4761,7 @@
 $as_echo "$ac_cv_target" >&6; }
 case $ac_cv_target in
 *-*-*) ;;
-*) as_fn_error $? "invalid value of canonical target" "$LINENO" 5;;
+*) as_fn_error $? "invalid value of canonical target" "$LINENO" 5 ;;
 esac
 target=$ac_cv_target
 ac_save_IFS=$IFS; IFS='-'
@@ -4572,7 +4786,7 @@
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing sem_close" >&5
 $as_echo_n "checking for library containing sem_close... " >&6; }
-if ${ac_cv_search_sem_close+:} false; then :
+if test "${ac_cv_search_sem_close+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_func_search_save_LIBS=$LIBS
@@ -4606,11 +4820,11 @@
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext
-  if ${ac_cv_search_sem_close+:} false; then :
+  if test "${ac_cv_search_sem_close+set}" = set; then :
   break
 fi
 done
-if ${ac_cv_search_sem_close+:} false; then :
+if test "${ac_cv_search_sem_close+set}" = set; then :
 
 else
   ac_cv_search_sem_close=no
@@ -4697,21 +4911,10 @@
      :end' >>confcache
 if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
   if test -w "$cache_file"; then
-    if test "x$cache_file" != "x/dev/null"; then
+    test "x$cache_file" != "x/dev/null" &&
       { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
 $as_echo "$as_me: updating cache $cache_file" >&6;}
-      if test ! -f "$cache_file" || test -h "$cache_file"; then
-	cat confcache >"$cache_file"
-      else
-        case $cache_file in #(
-        */* | ?:*)
-	  mv -f confcache "$cache_file"$$ &&
-	  mv -f "$cache_file"$$ "$cache_file" ;; #(
-        *)
-	  mv -f confcache "$cache_file" ;;
-	esac
-      fi
-    fi
+    cat confcache >$cache_file
   else
     { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
@@ -4743,7 +4946,7 @@
 
 
 
-: "${CONFIG_STATUS=./config.status}"
+: ${CONFIG_STATUS=./config.status}
 ac_write_fail=0
 ac_clean_files_save=$ac_clean_files
 ac_clean_files="$ac_clean_files $CONFIG_STATUS"
@@ -4844,7 +5047,6 @@
 IFS=" ""	$as_nl"
 
 # Find who we are.  Look in the path if we contain no directory separator.
-as_myself=
 case $0 in #((
   *[\\/]* ) as_myself=$0 ;;
   *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5152,7 +5354,7 @@
 # values after options handling.
 ac_log="
 This file was extended by Haskell unix package $as_me 2.0, which was
-generated by GNU Autoconf 2.68.  Invocation command line was
+generated by GNU Autoconf 2.67.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
@@ -5214,7 +5416,7 @@
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
 Haskell unix package config.status 2.0
-configured by $0, generated by GNU Autoconf 2.68,
+configured by $0, generated by GNU Autoconf 2.67,
   with options \\"\$ac_cs_config\\"
 
 Copyright (C) 2010 Free Software Foundation, Inc.
@@ -5337,7 +5539,7 @@
     "include/HsUnixConfig.h") CONFIG_HEADERS="$CONFIG_HEADERS include/HsUnixConfig.h" ;;
     "unix.buildinfo") CONFIG_FILES="$CONFIG_FILES unix.buildinfo" ;;
 
-  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
+  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5 ;;
   esac
 done
 
@@ -5359,10 +5561,9 @@
 # after its creation but before its name has been assigned to `$tmp'.
 $debug ||
 {
-  tmp= ac_tmp=
+  tmp=
   trap 'exit_status=$?
-  : "${ac_tmp:=$tmp}"
-  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
+  { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status
 ' 0
   trap 'as_fn_exit 1' 1 2 13 15
 }
@@ -5370,13 +5571,12 @@
 
 {
   tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
-  test -d "$tmp"
+  test -n "$tmp" && test -d "$tmp"
 }  ||
 {
   tmp=./conf$$-$RANDOM
   (umask 077 && mkdir "$tmp")
 } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
-ac_tmp=$tmp
 
 # Set up the scripts for CONFIG_FILES section.
 # No need to generate them if there are no CONFIG_FILES.
@@ -5398,7 +5598,7 @@
   ac_cs_awk_cr=$ac_cr
 fi
 
-echo 'BEGIN {' >"$ac_tmp/subs1.awk" &&
+echo 'BEGIN {' >"$tmp/subs1.awk" &&
 _ACEOF
 
 
@@ -5426,7 +5626,7 @@
 rm -f conf$$subs.sh
 
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&
+cat >>"\$tmp/subs1.awk" <<\\_ACAWK &&
 _ACEOF
 sed -n '
 h
@@ -5474,7 +5674,7 @@
 rm -f conf$$subs.awk
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 _ACAWK
-cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
+cat >>"\$tmp/subs1.awk" <<_ACAWK &&
   for (key in S) S_is_set[key] = 1
   FS = ""
 
@@ -5506,7 +5706,7 @@
   sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
 else
   cat
-fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \
+fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \
   || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
 _ACEOF
 
@@ -5540,7 +5740,7 @@
 # No need to generate them if there are no CONFIG_HEADERS.
 # This happens for instance with `./config.status Makefile'.
 if test -n "$CONFIG_HEADERS"; then
-cat >"$ac_tmp/defines.awk" <<\_ACAWK ||
+cat >"$tmp/defines.awk" <<\_ACAWK ||
 BEGIN {
 _ACEOF
 
@@ -5552,8 +5752,8 @@
 # handling of long lines.
 ac_delim='%!_!# '
 for ac_last_try in false false :; do
-  ac_tt=`sed -n "/$ac_delim/p" confdefs.h`
-  if test -z "$ac_tt"; then
+  ac_t=`sed -n "/$ac_delim/p" confdefs.h`
+  if test -z "$ac_t"; then
     break
   elif $ac_last_try; then
     as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
@@ -5654,7 +5854,7 @@
   esac
   case $ac_mode$ac_tag in
   :[FHL]*:*);;
-  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
+  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5 ;;
   :[FH]-) ac_tag=-:-;;
   :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
   esac
@@ -5673,7 +5873,7 @@
     for ac_f
     do
       case $ac_f in
-      -) ac_f="$ac_tmp/stdin";;
+      -) ac_f="$tmp/stdin";;
       *) # Look for the file first in the build tree, then in the source tree
 	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
 	 # because $ac_f cannot contain `:'.
@@ -5682,7 +5882,7 @@
 	   [\\/$]*) false;;
 	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
 	   esac ||
-	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5 ;;
       esac
       case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
       as_fn_append ac_file_inputs " '$ac_f'"
@@ -5708,8 +5908,8 @@
     esac
 
     case $ac_tag in
-    *:-:* | *:-) cat >"$ac_tmp/stdin" \
-      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
+    *:-:* | *:-) cat >"$tmp/stdin" \
+      || as_fn_error $? "could not create $ac_file" "$LINENO" 5  ;;
     esac
     ;;
   esac
@@ -5834,22 +6034,21 @@
 s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
 $ac_datarootdir_hack
 "
-eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
-  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \
+  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
 
 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
-  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
-  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' \
-      "$ac_tmp/out"`; test -z "$ac_out"; } &&
+  { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } &&
+  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } &&
   { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
 which seems to be undefined.  Please make sure it is defined" >&5
 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
 which seems to be undefined.  Please make sure it is defined" >&2;}
 
-  rm -f "$ac_tmp/stdin"
+  rm -f "$tmp/stdin"
   case $ac_file in
-  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
-  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
+  -) cat "$tmp/out" && rm -f "$tmp/out";;
+  *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";;
   esac \
   || as_fn_error $? "could not create $ac_file" "$LINENO" 5
  ;;
@@ -5860,20 +6059,20 @@
   if test x"$ac_file" != x-; then
     {
       $as_echo "/* $configure_input  */" \
-      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs"
-    } >"$ac_tmp/config.h" \
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs"
+    } >"$tmp/config.h" \
       || as_fn_error $? "could not create $ac_file" "$LINENO" 5
-    if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then
+    if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then
       { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
 $as_echo "$as_me: $ac_file is unchanged" >&6;}
     else
       rm -f "$ac_file"
-      mv "$ac_tmp/config.h" "$ac_file" \
+      mv "$tmp/config.h" "$ac_file" \
 	|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
     fi
   else
     $as_echo "/* $configure_input  */" \
-      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \
       || as_fn_error $? "could not create -" "$LINENO" 5
   fi
  ;;
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -28,11 +28,30 @@
 
 AC_CHECK_FUNCS([getgrgid_r getgrnam_r getpwnam_r getpwuid_r getpwnam getpwuid])
 AC_CHECK_FUNCS([getpwent getgrent])
-AC_CHECK_FUNCS([lchown setenv sysconf unsetenv])
+AC_CHECK_FUNCS([lchown setenv sysconf unsetenv clearenv])
 AC_CHECK_FUNCS([nanosleep])
 AC_CHECK_FUNCS([ptsname])
 AC_CHECK_FUNCS([setitimer])
 AC_CHECK_FUNCS([readdir_r])
+
+AC_CHECK_MEMBERS([struct stat.st_atim])
+AC_CHECK_MEMBERS([struct stat.st_mtim])
+AC_CHECK_MEMBERS([struct stat.st_ctim])
+AC_CHECK_MEMBERS([struct stat.st_atimespec])
+AC_CHECK_MEMBERS([struct stat.st_mtimespec])
+AC_CHECK_MEMBERS([struct stat.st_ctimespec])
+AC_CHECK_MEMBERS([struct stat.st_atimensec])
+AC_CHECK_MEMBERS([struct stat.st_mtimensec])
+AC_CHECK_MEMBERS([struct stat.st_ctimensec])
+AC_CHECK_MEMBERS([struct stat.st_atime_n])
+AC_CHECK_MEMBERS([struct stat.st_mtime_n])
+AC_CHECK_MEMBERS([struct stat.st_ctime_n])
+AC_CHECK_MEMBERS([struct stat.st_uatime])
+AC_CHECK_MEMBERS([struct stat.st_umtime])
+AC_CHECK_MEMBERS([struct stat.st_uctime])
+
+# Additional temp functions
+AC_CHECK_FUNCS([mkstemps mkdtemp])
 
 # Avoid adding rt if absent or unneeded
 AC_CHECK_LIB(rt, shm_open, [EXTRA_LIBS="$EXTRA_LIBS rt" CFLAGS="$CFLAGS -lrt"])
diff --git a/include/HsUnix.h b/include/HsUnix.h
--- a/include/HsUnix.h
+++ b/include/HsUnix.h
@@ -93,6 +93,9 @@
 #include <signal.h>
 #endif
 
+/* in Signals.c */
+extern HsInt nocldstop;
+
 extern char **environ;
 
 int __hsunix_wifexited   (int stat);
@@ -175,6 +178,14 @@
 
 #if !defined(__MINGW32__)
 int __hscore_mkstemp(char *filetemplate);
+#endif
+
+#if HAVE_MKSTEMPS
+int __hscore_mkstemps(char *filetemplate, int suffixlen);
+#endif
+
+#if HAVE_MKDTEMP
+char *__hscore_mkdtemp(char *filetemplate);
 #endif
 
 #if !defined(__MINGW32__) && !defined(irix_HOST_OS)
diff --git a/include/HsUnixConfig.h b/include/HsUnixConfig.h
--- a/include/HsUnixConfig.h
+++ b/include/HsUnixConfig.h
@@ -95,8 +95,11 @@
 #define CONST_SIG_UNBLOCK 1
 
 /* Define to 1 if you have the <bsd/libutil.h> header file. */
-#define HAVE_BSD_LIBUTIL_H 1
+/* #undef HAVE_BSD_LIBUTIL_H */
 
+/* Define to 1 if you have the `clearenv' function. */
+#define HAVE_CLEARENV 1
+
 /* Define if we have /dev/ptc. */
 /* #undef HAVE_DEV_PTC */
 
@@ -151,6 +154,12 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #define HAVE_MEMORY_H 1
 
+/* Define to 1 if you have the `mkdtemp' function. */
+#define HAVE_MKDTEMP 1
+
+/* Define to 1 if you have the `mkstemps' function. */
+#define HAVE_MKSTEMPS 1
+
 /* Define to 1 if you have the `nanosleep' function. */
 #define HAVE_NANOSLEEP 1
 
@@ -197,10 +206,10 @@
 #define HAVE_SETITIMER 1
 
 /* Define to 1 if you have the `shm_open' function. */
-/* #undef HAVE_SHM_OPEN */
+#define HAVE_SHM_OPEN 1
 
 /* Define to 1 if you have the `shm_unlink' function. */
-/* #undef HAVE_SHM_UNLINK */
+#define HAVE_SHM_UNLINK 1
 
 /* Define to 1 if you have the <signal.h> header file. */
 #define HAVE_SIGNAL_H 1
@@ -217,6 +226,51 @@
 /* Define to 1 if you have the <string.h> header file. */
 #define HAVE_STRING_H 1
 
+/* Define to 1 if `st_atim' is a member of `struct stat'. */
+#define HAVE_STRUCT_STAT_ST_ATIM 1
+
+/* Define to 1 if `st_atimensec' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_ATIMENSEC */
+
+/* Define to 1 if `st_atimespec' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_ATIMESPEC */
+
+/* Define to 1 if `st_atime_n' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_ATIME_N */
+
+/* Define to 1 if `st_ctim' is a member of `struct stat'. */
+#define HAVE_STRUCT_STAT_ST_CTIM 1
+
+/* Define to 1 if `st_ctimensec' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_CTIMENSEC */
+
+/* Define to 1 if `st_ctimespec' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_CTIMESPEC */
+
+/* Define to 1 if `st_ctime_n' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_CTIME_N */
+
+/* Define to 1 if `st_mtim' is a member of `struct stat'. */
+#define HAVE_STRUCT_STAT_ST_MTIM 1
+
+/* Define to 1 if `st_mtimensec' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_MTIMENSEC */
+
+/* Define to 1 if `st_mtimespec' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_MTIMESPEC */
+
+/* Define to 1 if `st_mtime_n' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_MTIME_N */
+
+/* Define to 1 if `st_uatime' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_UATIME */
+
+/* Define to 1 if `st_uctime' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_UCTIME */
+
+/* Define to 1 if `st_umtime' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_UMTIME */
+
 /* Define to 1 if you have the `sysconf' function. */
 #define HAVE_SYSCONF 1
 
@@ -287,7 +341,7 @@
 /* #undef USLEEP_RETURNS_VOID */
 
 /* Number of bits in a file offset, on hosts where this is settable. */
-#define _FILE_OFFSET_BITS 64
+/* #undef _FILE_OFFSET_BITS */
 
 /* Define for large files, on AIX-style hosts. */
 /* #undef _LARGE_FILES */
diff --git a/include/HsUnixConfig.h.in b/include/HsUnixConfig.h.in
--- a/include/HsUnixConfig.h.in
+++ b/include/HsUnixConfig.h.in
@@ -96,6 +96,9 @@
 /* Define to 1 if you have the <bsd/libutil.h> header file. */
 #undef HAVE_BSD_LIBUTIL_H
 
+/* Define to 1 if you have the `clearenv' function. */
+#undef HAVE_CLEARENV
+
 /* Define if we have /dev/ptc. */
 #undef HAVE_DEV_PTC
 
@@ -150,6 +153,12 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if you have the `mkdtemp' function. */
+#undef HAVE_MKDTEMP
+
+/* Define to 1 if you have the `mkstemps' function. */
+#undef HAVE_MKSTEMPS
+
 /* Define to 1 if you have the `nanosleep' function. */
 #undef HAVE_NANOSLEEP
 
@@ -215,6 +224,51 @@
 
 /* Define to 1 if you have the <string.h> header file. */
 #undef HAVE_STRING_H
+
+/* Define to 1 if `st_atim' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_ATIM
+
+/* Define to 1 if `st_atimensec' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_ATIMENSEC
+
+/* Define to 1 if `st_atimespec' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_ATIMESPEC
+
+/* Define to 1 if `st_atime_n' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_ATIME_N
+
+/* Define to 1 if `st_ctim' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_CTIM
+
+/* Define to 1 if `st_ctimensec' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_CTIMENSEC
+
+/* Define to 1 if `st_ctimespec' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_CTIMESPEC
+
+/* Define to 1 if `st_ctime_n' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_CTIME_N
+
+/* Define to 1 if `st_mtim' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_MTIM
+
+/* Define to 1 if `st_mtimensec' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_MTIMENSEC
+
+/* Define to 1 if `st_mtimespec' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_MTIMESPEC
+
+/* Define to 1 if `st_mtime_n' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_MTIME_N
+
+/* Define to 1 if `st_uatime' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_UATIME
+
+/* Define to 1 if `st_uctime' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_UCTIME
+
+/* Define to 1 if `st_umtime' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_UMTIME
 
 /* Define to 1 if you have the `sysconf' function. */
 #undef HAVE_SYSCONF
diff --git a/unix.cabal b/unix.cabal
--- a/unix.cabal
+++ b/unix.cabal
@@ -1,5 +1,5 @@
 name:		unix
-version:        2.5.1.1
+version:        2.6.0.0
 license:	BSD3
 license-file:	LICENSE
 maintainer:	libraries@haskell.org
@@ -77,8 +77,9 @@
         System.Posix.Process.Common
         System.Posix.Terminal.Common
 
-    build-depends:      base >= 4.2 && < 4.6,
-                        bytestring >= 0.9.2.0 && < 0.10
+    build-depends:      base >= 4.2 && < 4.7,
+                        bytestring >= 0.9.2.0 && < 0.11,
+                        time
     extensions: CPP, ForeignFunctionInterface, EmptyDataDecls
     if impl(ghc >= 7.1)
         extensions: NondecreasingIndentation
