diff options
author | Ian Lynagh <igloo@earth.li> | 2009-08-09 13:47:17 +0000 |
---|---|---|
committer | Ian Lynagh <igloo@earth.li> | 2009-08-09 13:47:17 +0000 |
commit | 37444277e988c12f552d55773731d8d76f4193d2 (patch) | |
tree | 5b88657cad34c6b267bab02160a7b47d665f6d25 /libraries/base/System/IO.hs | |
parent | 2e1f1454244c9dc9f5f414ce38dd133da56e2c37 (diff) | |
download | haskell-37444277e988c12f552d55773731d8d76f4193d2.tar.gz |
Apply proposal #3393
Add openTempFileWithDefaultPermissions and
openBinaryTempFileWithDefaultPermissions.
Diffstat (limited to 'libraries/base/System/IO.hs')
-rw-r--r-- | libraries/base/System/IO.hs | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/libraries/base/System/IO.hs b/libraries/base/System/IO.hs index 47e9213bf9..ed75bb0b49 100644 --- a/libraries/base/System/IO.hs +++ b/libraries/base/System/IO.hs @@ -159,6 +159,8 @@ module System.IO ( openTempFile, openBinaryTempFile, + openTempFileWithDefaultPermissions, + openBinaryTempFileWithDefaultPermissions, #if !defined(__NHC__) && !defined(__HUGS__) -- * Unicode encoding\/decoding @@ -227,6 +229,7 @@ import Data.Maybe import Foreign.C.Error import Foreign.C.Types import System.Posix.Internals +import System.Posix.Types #endif #ifdef __GLASGOW_HASKELL__ @@ -487,14 +490,29 @@ openTempFile :: FilePath -- ^ Directory in which to create the file -- 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 @@ -531,7 +549,7 @@ openTempFile' loc tmp_dir template binary = do #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 |