Commit 71dea322 authored by sof's avatar sof
Browse files

[project @ 2001-08-14 17:14:22 by sof]

Don't use 'foreign label' to get at prog_arg{v,c}, use
the RtsAPI-provided getProgArgv().
parent eca4400f
-- ----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
-- $Id: System.lhs,v 1.32 2001/08/10 13:48:06 simonmar Exp $ -- $Id: System.lhs,v 1.33 2001/08/14 17:14:22 sof Exp $
-- --
-- (c) The University of Glasgow, 1994-2000 -- (c) The University of Glasgow, 1994-2000
-- --
...@@ -22,6 +22,7 @@ import PrelCError ...@@ -22,6 +22,7 @@ import PrelCError
import PrelCString import PrelCString
import PrelCTypes import PrelCTypes
import PrelMarshalArray import PrelMarshalArray
import PrelMarshalAlloc
import PrelPtr import PrelPtr
import PrelStorable import PrelStorable
import PrelIOBase import PrelIOBase
...@@ -34,21 +35,27 @@ import PrelConc ...@@ -34,21 +35,27 @@ import PrelConc
-- line arguments (not including the program name). -- line arguments (not including the program name).
getArgs :: IO [String] getArgs :: IO [String]
getArgs = do getArgs =
argv <- peek prog_argv_label alloca $ \ p_argc ->
argc <- peek prog_argc_label alloca $ \ p_argv -> do
peekArray (fromIntegral argc - 1) (advancePtr argv 1) >>= mapM peekCString getProgArgv p_argc p_argv
p <- peek p_argc
foreign label "prog_argv" prog_argv_label :: Ptr (Ptr (Ptr CChar)) argv <- peek p_argv
foreign label "prog_argc" prog_argc_label :: Ptr CInt peekArray (p - 1) (advancePtr argv 1) >>= mapM peekCString
foreign import "getProgArgv" getProgArgv :: Ptr Int -> Ptr (Ptr CString) -> IO ()
-- Computation `getProgName' returns the name of the program -- Computation `getProgName' returns the name of the program
-- as it was invoked. -- as it was invoked.
getProgName :: IO String getProgName :: IO String
getProgName = do getProgName =
argv <- peek prog_argv_label alloca $ \ p_argc ->
unpackProgName argv alloca $ \ p_argv -> do
getProgArgv p_argc p_argv
argv <- peek p_argv
unpackProgName argv
-- Computation `getEnv var' returns the value -- Computation `getEnv var' returns the value
-- of the environment variable {\em var}. -- of the environment variable {\em var}.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment