{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE StandaloneDeriving #-}
module GHC.Internal.IO.SubSystem (
withIoSubSystem,
withIoSubSystem',
whenIoSubSystem,
ioSubSystem,
IoSubSystem(..),
conditional,
(<!>),
isWindowsNativeIO
) where
import GHC.Internal.Base
import GHC.Internal.Show
import GHC.Internal.Enum
#if defined(mingw32_HOST_OS)
import GHC.Internal.IO.Unsafe
import GHC.Internal.Foreign.Ptr
import GHC.Internal.Foreign.Storable
import GHC.Internal.Foreign.C.Types
import GHC.Internal.Foreign.Marshal.Utils
#endif
infixl 7 <!>
data IoSubSystem
= IoPOSIX
| IoNative
deriving (IoSubSystem -> IoSubSystem -> Bool
(IoSubSystem -> IoSubSystem -> Bool)
-> (IoSubSystem -> IoSubSystem -> Bool) -> Eq IoSubSystem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IoSubSystem -> IoSubSystem -> Bool
== :: IoSubSystem -> IoSubSystem -> Bool
$c/= :: IoSubSystem -> IoSubSystem -> Bool
/= :: IoSubSystem -> IoSubSystem -> Bool
Eq)
deriving instance Enum IoSubSystem
deriving instance Show IoSubSystem
conditional :: a -> a -> a
#if defined(mingw32_HOST_OS)
conditional :: forall a. a -> a -> a
conditional a
posix a
windows =
case IoSubSystem
ioSubSystem of
IoSubSystem
IoPOSIX -> a
posix
IoSubSystem
IoNative -> a
windows
#else
conditional posix _ = posix
#endif
(<!>) :: a -> a -> a
<!> :: forall a. a -> a -> a
(<!>) = a -> a -> a
forall a. a -> a -> a
conditional
isWindowsNativeIO :: Bool
isWindowsNativeIO :: Bool
isWindowsNativeIO = Bool
False Bool -> Bool -> Bool
forall a. a -> a -> a
<!> Bool
True
ioSubSystem :: IoSubSystem
#if defined(mingw32_HOST_OS)
{-# INLINE ioSubSystem #-}
ioSubSystem :: IoSubSystem
ioSubSystem =
case CBool -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool CBool
ioManagerIsWin32NativeCBool of
Bool
False -> IoSubSystem
IoPOSIX
Bool
True -> IoSubSystem
IoNative
{-# NOINLINE ioManagerIsWin32NativeCBool #-}
ioManagerIsWin32NativeCBool :: CBool
ioManagerIsWin32NativeCBool :: CBool
ioManagerIsWin32NativeCBool =
IO CBool -> CBool
forall a. IO a -> a
unsafeDupablePerformIO (IO CBool -> CBool) -> IO CBool -> CBool
forall a b. (a -> b) -> a -> b
$ Ptr CBool -> IO CBool
forall a. Storable a => Ptr a -> IO a
peek Ptr CBool
ioManagerIsWin32NativePtr
foreign import ccall "&rts_IOManagerIsWin32Native"
ioManagerIsWin32NativePtr :: Ptr CBool
#else
ioSubSystem = IoPOSIX
#endif
withIoSubSystem :: (IoSubSystem -> IO a) -> IO a
withIoSubSystem :: forall a. (IoSubSystem -> IO a) -> IO a
withIoSubSystem IoSubSystem -> IO a
f = IoSubSystem -> IO a
f IoSubSystem
ioSubSystem
withIoSubSystem' :: (IoSubSystem -> a) -> a
withIoSubSystem' :: forall a. (IoSubSystem -> a) -> a
withIoSubSystem' IoSubSystem -> a
f = IoSubSystem -> a
f IoSubSystem
ioSubSystem
whenIoSubSystem :: IoSubSystem -> IO () -> IO ()
whenIoSubSystem :: IoSubSystem -> IO () -> IO ()
whenIoSubSystem IoSubSystem
m IO ()
f = do let sub :: IoSubSystem
sub = IoSubSystem
ioSubSystem
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (IoSubSystem
sub IoSubSystem -> IoSubSystem -> Bool
forall a. Eq a => a -> a -> Bool
== IoSubSystem
m) IO ()
f