Initialize hs_init with UTF8 encoded arguments on Windows.
[ghc.git] / libraries / base / GHC / Environment.hs
1 {-# LANGUAGE Trustworthy #-}
2 {-# LANGUAGE NoImplicitPrelude #-}
3 {-# LANGUAGE CPP #-}
4
5 module GHC.Environment (getFullArgs) where
6
7 import Foreign
8 import Foreign.C
9 import GHC.Base
10 import GHC.Real ( fromIntegral )
11 import GHC.IO.Encoding
12 import qualified GHC.Foreign as GHC
13
14 #if defined(mingw32_HOST_OS)
15 # if defined(i386_HOST_ARCH)
16 # define WINDOWS_CCONV stdcall
17 # elif defined(x86_64_HOST_ARCH)
18 # define WINDOWS_CCONV ccall
19 # else
20 # error Unknown mingw32 arch
21 # endif
22 #endif
23
24 -- | Computation 'getFullArgs' is the "raw" version of 'getArgs', similar
25 -- to @argv@ in other languages. It returns a list of the program's
26 -- command line arguments, starting with the program name, and
27 -- including those normally eaten by the RTS (+RTS ... -RTS).
28 getFullArgs :: IO [String]
29 getFullArgs = do
30 alloca $ \ p_argc -> do
31 alloca $ \ p_argv -> do
32 getFullProgArgv p_argc p_argv
33 p <- fromIntegral `liftM` peek p_argc
34 argv <- peek p_argv
35 enc <- argvEncoding
36 peekArray p argv >>= mapM (GHC.peekCString enc)
37
38 foreign import ccall unsafe "getFullProgArgv"
39 getFullProgArgv :: Ptr CInt -> Ptr (Ptr CString) -> IO ()