From a8d4731456ac3da0a70399e4ab821a763a4c04fb Mon Sep 17 00:00:00 2001 From: Max Bolingbroke <batterseapower@hotmail.com> Date: Wed, 6 Apr 2011 07:57:21 +0100 Subject: [PATCH] Use _NSGetEnviron on OS X: fixes #2458 --- System/Posix/Env.hsc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/System/Posix/Env.hsc b/System/Posix/Env.hsc index 39db08c..83bdc2c 100644 --- a/System/Posix/Env.hsc +++ b/System/Posix/Env.hsc @@ -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. -- GitLab