shithub: MicroHs

ref: a29aeb7b470b51a212e225b7fe2d5233533b0269
dir: /lib/System/Environment.hs/

View raw version
-- Copyright 2023 Lennart Augustsson
-- See LICENSE file for full license.
module System.Environment(module System.Environment) where
import Prelude
import Primitives
import Foreign.C.String
import Foreign.Ptr

getArgs :: IO [String]
getArgs = primGetArgs

withDropArgs :: forall a . Int -> IO a -> IO a
withDropArgs = primWithDropArgs

foreign import ccall "getenv" c_getenv :: CString -> IO CString

lookupEnv :: String -> IO (Maybe String)
lookupEnv var = do
  cptr <- withCAString var c_getenv
  if cptr == nullPtr then
    return Nothing
   else
    Just <$> peekCAString cptr