Skip to content
Snippets Groups Projects
Commit a8d47314 authored by batterseapower's avatar batterseapower
Browse files

Use _NSGetEnviron on OS X: fixes #2458

parent 93f0e195
No related branches found
No related tags found
No related merge requests found
......@@ -55,12 +55,24 @@ foreign import ccall unsafe "getenv"
getEnvironmentPrim :: IO [String]
getEnvironmentPrim = do
c_environ <- peek c_environ_p
c_environ <- getCEnviron
arr <- peekArray0 nullPtr c_environ
mapM peekCString arr
getCEnviron :: IO (Ptr CString)
#if darwin_HOST_OS
-- You should not access _environ directly on Darwin in a bundle/shared library.
-- See #2458 and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html
getCEnviron = nsGetEnviron >>= peek
foreign import ccall unsafe "_NSGetEnviron"
nsGetEnviron :: IO (Ptr (Ptr CString))
#else
getCEnviron = peek c_environ_p
foreign import ccall unsafe "&environ"
c_environ_p :: Ptr (Ptr CString)
#endif
-- |'getEnvironment' retrieves the entire environment as a
-- list of @(key,value)@ pairs.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment