From eaa2e8d592b484b40269cf6b104d68cf7b230670 Mon Sep 17 00:00:00 2001 From: Lennart Augustsson Date: Thu, 26 Sep 2024 09:56:48 +0200 Subject: [PATCH] Add openBinaryTempFile --- lib/System/IO.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/System/IO.hs b/lib/System/IO.hs index a5c900ef..49ba401a 100644 --- a/lib/System/IO.hs +++ b/lib/System/IO.hs @@ -21,7 +21,7 @@ module System.IO( mkTextEncoding, hSetEncoding, utf8, - openTmpFile, openTempFile, + openTmpFile, openTempFile, openBinaryTempFile, withFile, ) where @@ -301,8 +301,8 @@ openTmpFile tmpl = do return (tmp, h) -- Sloppy implementation of openTempFile -openTempFile :: FilePath -> String -> IO (String, Handle) -openTempFile tmp tmplt = do +openTempFile' :: (FilePath -> IOMode -> IO Handle) -> FilePath -> String -> IO (String, Handle) +openTempFile' open tmp tmplt = do let (pre, suf) = splitTmp tmplt loop n = do let fn = tmp ++ "/" ++ pre ++ show n ++ suf @@ -312,6 +312,12 @@ openTempFile tmp tmplt = do hClose h loop (n+1 :: Int) Nothing -> do - h <- openFile fn ReadWriteMode + h <- open fn ReadWriteMode return (fn, h) loop 0 + +openTempFile :: FilePath -> String -> IO (String, Handle) +openTempFile = openTempFile' openFile + +openBinaryTempFile :: FilePath -> String -> IO (String, Handle) +openBinaryTempFile = openTempFile' openBinaryFile