openTempFile,
openBinaryTempFile,
+ openTempFileWithDefaultPermissions,
+ openBinaryTempFileWithDefaultPermissions,
#if !defined(__NHC__) && !defined(__HUGS__)
-- * Unicode encoding\/decoding
--
-- The default 'TextEncoding' is the same as the default encoding
-- on your system, which is also available as 'localeEncoding'.
- -- (GHC note: on Windows, currently 'localeEncoding' is always
- -- 'latin1'; there is no support for encoding and decoding using
- -- the ANSI code page).
+ -- (GHC note: on Windows, we currently do not support double-byte
+ -- encodings; if the console\'s code page is unsupported, then
+ -- 'localeEncoding' will be 'latin1'.)
--
-- Encoding and decoding errors are always detected and reported,
-- except during lazy I/O ('hGetContents', 'getContents', and
-- termination of the character stream, as with other I/O errors.
hSetEncoding,
+ hGetEncoding,
-- ** Unicode encodings
TextEncoding,
latin1,
- utf8,
+ utf8, utf8_bom,
utf16, utf16le, utf16be,
utf32, utf32le, utf32be,
localeEncoding,
import Foreign.C.Error
import Foreign.C.Types
import System.Posix.Internals
+import System.Posix.Types
#endif
#ifdef __GLASGOW_HASKELL__
import GHC.IORef
import GHC.IO.Exception ( userError )
import GHC.IO.Encoding
-import GHC.Exception
import GHC.Num
import Text.Read
import GHC.Show
-- the created file will be \"fooXXX.ext\" where XXX is some
-- random number.
-> IO (FilePath, Handle)
-openTempFile tmp_dir template = openTempFile' "openTempFile" tmp_dir template False
+openTempFile tmp_dir template
+ = openTempFile' "openTempFile" tmp_dir template False 0o600
-- | Like 'openTempFile', but opens the file in binary mode. See 'openBinaryFile' for more comments.
openBinaryTempFile :: FilePath -> String -> IO (FilePath, Handle)
-openBinaryTempFile tmp_dir template = openTempFile' "openBinaryTempFile" tmp_dir template True
-
-openTempFile' :: String -> FilePath -> String -> Bool -> IO (FilePath, Handle)
-openTempFile' loc tmp_dir template binary = do
+openBinaryTempFile tmp_dir template
+ = openTempFile' "openBinaryTempFile" tmp_dir template True 0o600
+
+-- | Like 'openTempFile', but uses the default file permissions
+openTempFileWithDefaultPermissions :: FilePath -> String
+ -> IO (FilePath, Handle)
+openTempFileWithDefaultPermissions tmp_dir template
+ = openTempFile' "openBinaryTempFile" tmp_dir template False 0o666
+
+-- | Like 'openBinaryTempFile', but uses the default file permissions
+openBinaryTempFileWithDefaultPermissions :: FilePath -> String
+ -> IO (FilePath, Handle)
+openBinaryTempFileWithDefaultPermissions tmp_dir template
+ = openTempFile' "openBinaryTempFile" tmp_dir template True 0o666
+
+openTempFile' :: String -> FilePath -> String -> Bool -> CMode
+ -> IO (FilePath, Handle)
+openTempFile' loc tmp_dir template binary mode = do
pid <- c_getpid
findTempName pid
where
#else
findTempName x = do
fd <- withFilePath filepath $ \ f ->
- c_open f oflags 0o600
+ c_open f oflags mode
if fd < 0
then do
errno <- getErrno