{-# 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 = POSIX.stdin <!> Win.stdin
#else
stdin :: Handle
stdin = Handle
POSIX.stdin
#endif
stdout :: Handle
#if defined(mingw32_HOST_OS)
stdout = POSIX.stdout <!> Win.stdout
#else
stdout :: Handle
stdout = Handle
POSIX.stdout
#endif
stderr :: Handle
#if defined(mingw32_HOST_OS)
stderr = POSIX.stderr <!> Win.stderr
#else
stderr :: Handle
stderr = Handle
POSIX.stderr
#endif
openFile
:: FilePath
-> IOMode
-> IO Handle
#if defined(mingw32_HOST_OS)
openFile = POSIX.openFile <!> Win.openFile
#else
openFile :: FilePath -> IOMode -> IO Handle
openFile = FilePath -> IOMode -> IO Handle
POSIX.openFile
#endif
openBinaryFile
:: FilePath
-> IOMode
-> IO Handle
#if defined(mingw32_HOST_OS)
openBinaryFile = POSIX.openBinaryFile <!> Win.openBinaryFile
#else
openBinaryFile :: FilePath -> IOMode -> IO Handle
openBinaryFile = FilePath -> IOMode -> IO Handle
POSIX.openBinaryFile
#endif
withFile
:: FilePath
-> IOMode
-> (Handle -> IO r)
-> IO r
#if defined(mingw32_HOST_OS)
withFile = POSIX.withFile <!> wf
where
wf path mode act = bracket (Win.openFile path mode) hClose_impl act
#else
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
#endif
withBinaryFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r
#if defined(mingw32_HOST_OS)
withBinaryFile = POSIX.withBinaryFile <!> wf
where
wf path mode act = bracket (Win.openBinaryFile path mode) hClose_impl act
#else
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
#endif
openFileBlocking :: FilePath -> IOMode -> IO Handle
#if defined(mingw32_HOST_OS)
openFileBlocking = POSIX.openFileBlocking <!> Win.openFileBlocking
#else
openFileBlocking :: FilePath -> IOMode -> IO Handle
openFileBlocking = FilePath -> IOMode -> IO Handle
POSIX.openFileBlocking
#endif
withFileBlocking :: FilePath -> IOMode -> (Handle -> IO r) -> IO r
#if defined(mingw32_HOST_OS)
withFileBlocking = POSIX.withFileBlocking <!> wf
where
wf path mode act = bracket (Win.openFileBlocking path mode) hClose_impl act
#else
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
#endif