{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE CPP #-}
module GHC.Internal.IO.StdHandles
(
stdin, stdout, stderr,
openFile, openBinaryFile, openFileBlocking,
withFile, withBinaryFile, withFileBlocking
) where
import GHC.Internal.IO
import GHC.Internal.IO.IOMode
import GHC.Internal.IO.Handle.Types
import qualified GHC.Internal.IO.Handle.FD as POSIX
#if defined(mingw32_HOST_OS)
import GHC.Internal.IO.SubSystem
import qualified GHC.Internal.IO.Handle.Windows as Win
import GHC.Internal.IO.Handle.Internals (hClose_impl)
#endif
stdin :: Handle
#if defined(mingw32_HOST_OS)
stdin :: Handle
stdin = Handle
POSIX.stdin Handle -> Handle -> Handle
forall a. a -> a -> a
<!> Handle
Win.stdin
#else
stdin = POSIX.stdin
#endif
stdout :: Handle
#if defined(mingw32_HOST_OS)
stdout :: Handle
stdout = Handle
POSIX.stdout Handle -> Handle -> Handle
forall a. a -> a -> a
<!> Handle
Win.stdout
#else
stdout = POSIX.stdout
#endif
stderr :: Handle
#if defined(mingw32_HOST_OS)
stderr :: Handle
stderr = Handle
POSIX.stderr Handle -> Handle -> Handle
forall a. a -> a -> a
<!> Handle
Win.stderr
#else
stderr = POSIX.stderr
#endif
openFile
:: FilePath
-> IOMode
-> IO Handle
#if defined(mingw32_HOST_OS)
openFile :: FilePath -> IOMode -> IO Handle
openFile = FilePath -> IOMode -> IO Handle
POSIX.openFile (FilePath -> IOMode -> IO Handle)
-> (FilePath -> IOMode -> IO Handle)
-> FilePath
-> IOMode
-> IO Handle
forall a. a -> a -> a
<!> FilePath -> IOMode -> IO Handle
Win.openFile
#else
openFile = POSIX.openFile
#endif
openBinaryFile
:: FilePath
-> IOMode
-> IO Handle
#if defined(mingw32_HOST_OS)
openBinaryFile :: FilePath -> IOMode -> IO Handle
openBinaryFile = FilePath -> IOMode -> IO Handle
POSIX.openBinaryFile (FilePath -> IOMode -> IO Handle)
-> (FilePath -> IOMode -> IO Handle)
-> FilePath
-> IOMode
-> IO Handle
forall a. a -> a -> a
<!> FilePath -> IOMode -> IO Handle
Win.openBinaryFile
#else
openBinaryFile = POSIX.openBinaryFile
#endif
withFile
:: FilePath
-> IOMode
-> (Handle -> IO r)
-> IO r
#if defined(mingw32_HOST_OS)
withFile :: forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
withFile = FilePath -> IOMode -> (Handle -> IO r) -> IO r
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
POSIX.withFile (FilePath -> IOMode -> (Handle -> IO r) -> IO r)
-> (FilePath -> IOMode -> (Handle -> IO r) -> IO r)
-> FilePath
-> IOMode
-> (Handle -> IO r)
-> IO r
forall a. a -> a -> a
<!> FilePath -> IOMode -> (Handle -> IO r) -> IO r
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
wf
where
wf :: FilePath -> IOMode -> (Handle -> IO c) -> IO c
wf FilePath
path IOMode
mode Handle -> IO c
act = IO Handle -> (Handle -> IO ()) -> (Handle -> IO c) -> IO c
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (FilePath -> IOMode -> IO Handle
Win.openFile FilePath
path IOMode
mode) Handle -> IO ()
hClose_impl Handle -> IO c
act
#else
withFile = POSIX.withFile
#endif
withBinaryFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r
#if defined(mingw32_HOST_OS)
withBinaryFile :: forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
withBinaryFile = FilePath -> IOMode -> (Handle -> IO r) -> IO r
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
POSIX.withBinaryFile (FilePath -> IOMode -> (Handle -> IO r) -> IO r)
-> (FilePath -> IOMode -> (Handle -> IO r) -> IO r)
-> FilePath
-> IOMode
-> (Handle -> IO r)
-> IO r
forall a. a -> a -> a
<!> FilePath -> IOMode -> (Handle -> IO r) -> IO r
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
wf
where
wf :: FilePath -> IOMode -> (Handle -> IO c) -> IO c
wf FilePath
path IOMode
mode Handle -> IO c
act = IO Handle -> (Handle -> IO ()) -> (Handle -> IO c) -> IO c
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (FilePath -> IOMode -> IO Handle
Win.openBinaryFile FilePath
path IOMode
mode) Handle -> IO ()
hClose_impl Handle -> IO c
act
#else
withBinaryFile = POSIX.withBinaryFile
#endif
openFileBlocking :: FilePath -> IOMode -> IO Handle
#if defined(mingw32_HOST_OS)
openFileBlocking :: FilePath -> IOMode -> IO Handle
openFileBlocking = FilePath -> IOMode -> IO Handle
POSIX.openFileBlocking (FilePath -> IOMode -> IO Handle)
-> (FilePath -> IOMode -> IO Handle)
-> FilePath
-> IOMode
-> IO Handle
forall a. a -> a -> a
<!> FilePath -> IOMode -> IO Handle
Win.openFileBlocking
#else
openFileBlocking = POSIX.openFileBlocking
#endif
withFileBlocking :: FilePath -> IOMode -> (Handle -> IO r) -> IO r
#if defined(mingw32_HOST_OS)
withFileBlocking :: forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
withFileBlocking = FilePath -> IOMode -> (Handle -> IO r) -> IO r
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
POSIX.withFileBlocking (FilePath -> IOMode -> (Handle -> IO r) -> IO r)
-> (FilePath -> IOMode -> (Handle -> IO r) -> IO r)
-> FilePath
-> IOMode
-> (Handle -> IO r)
-> IO r
forall a. a -> a -> a
<!> FilePath -> IOMode -> (Handle -> IO r) -> IO r
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
wf
where
wf :: FilePath -> IOMode -> (Handle -> IO c) -> IO c
wf FilePath
path IOMode
mode Handle -> IO c
act = IO Handle -> (Handle -> IO ()) -> (Handle -> IO c) -> IO c
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (FilePath -> IOMode -> IO Handle
Win.openFileBlocking FilePath
path IOMode
mode) Handle -> IO ()
hClose_impl Handle -> IO c
act
#else
withFileBlocking = POSIX.withFileBlocking
#endif