hGetBufNonBlocking, -- :: Handle -> Ptr a -> Int -> IO Int
#endif
- -- * Temporary files (not portable: GHC\/Hugs only)
+ -- * Temporary files
-#if !defined(__NHC__)
openTempFile,
openBinaryTempFile,
-#endif
) where
#ifndef __NHC__
hSetBinaryMode _ _ = return ()
#endif
-#ifndef __NHC__
-- | The function creates a temporary file in ReadWrite mode.
-- The created file isn\'t deleted automatically, so you need to delete it manually.
--
-- beginning with '.' as the second component.
_ -> error "bug in System.IO.openTempFile"
+#ifndef __NHC__
oflags1 = rw_flags .|. o_EXCL
binary_flags
| otherwise = 0
oflags = oflags1 .|. binary_flags
+#endif
+#ifdef __NHC__
+ findTempName x = do h <- openFile filepath ReadWriteMode
+ return (filepath, h)
+#else
findTempName x = do
fd <- withCString filepath $ \ f ->
c_open f oflags 0o600
h <- fdToHandle fd
`ExceptionBase.catchException` \e -> do c_close fd; throw e
return (filepath, h)
+#endif
where
filename = prefix ++ show x ++ suffix
filepath = tmp_dir `combine` filename
pathSeparator = '/'
#endif
+#ifndef __NHC__
-- XXX Copied from GHC.Handle
std_flags = o_NONBLOCK .|. o_NOCTTY
output_flags = std_flags .|. o_CREAT
append_flags = write_flags .|. o_APPEND
#endif
+#ifdef __NHC__
+foreign import ccall "getpid" c_getpid :: IO Int
+#endif
+
-- $locking
-- Implementations should enforce as far as possible, at least locally to the
-- Haskell process, multiple-reader single-writer locking on files.