shithub: MicroHs

Download patch

ref: 53362c02342a4582377af1b586ac92f11c6a8d1c
parent: 4351551503d2e4db1d53d0f0f321341f91a9eb79
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Sat Feb 10 13:35:42 EST 2024

Add doesFileExist

--- a/lib/System/Directory.hs
+++ b/lib/System/Directory.hs
@@ -1,8 +1,9 @@
-module System.Directory(removeFile) where
+module System.Directory(removeFile, doesFileExist) where
 import Prelude
 import Control.Monad(when)
 import Foreign.C.String
 import Foreign.Ptr
+import System.IO
 
 foreign import ccall "unlink" c_unlink :: CString -> IO Int
 
@@ -11,3 +12,10 @@
   r <- withCAString fn c_unlink
   when (r /= 0) $
     error "removeFile failed"
+
+doesFileExist :: FilePath -> IO Bool
+doesFileExist fn = do
+  mh <- openFileM fn ReadMode
+  case mh of
+    Nothing -> return False
+    Just h  -> do { hClose h; return True }
--