{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE CPP #-}
module GHC.Environment (getFullArgs) where
import Foreign
import Foreign.C
import GHC.Base
import GHC.Real ( fromIntegral )
import GHC.IO.Encoding
import qualified GHC.Foreign as GHC
#if defined(mingw32_HOST_OS)
# if defined(i386_HOST_ARCH)
# define WINDOWS_CCONV stdcall
# elif defined(x86_64_HOST_ARCH)
# define WINDOWS_CCONV ccall
# else
# error Unknown mingw32 arch
# endif
#endif
getFullArgs :: IO [String]
getFullArgs :: IO [String]
getFullArgs =
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \ Ptr CInt
p_argc ->
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \ Ptr (Ptr CString)
p_argv -> do
Ptr CInt -> Ptr (Ptr CString) -> IO ()
getFullProgArgv Ptr CInt
p_argc Ptr (Ptr CString)
p_argv
Int
p <- forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
p_argc
Ptr CString
argv <- forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr CString)
p_argv
TextEncoding
enc <- IO TextEncoding
argvEncoding
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
p Ptr CString
argv forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (TextEncoding -> CString -> IO String
GHC.peekCString TextEncoding
enc)
foreign import ccall unsafe "getFullProgArgv"
getFullProgArgv :: Ptr CInt -> Ptr (Ptr CString) -> IO ()