aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Max Bolingbroke <batterseapower@hotmail.com>2011-04-06 07:57:21 +0100
committerGravatar Max Bolingbroke <batterseapower@hotmail.com>2011-04-06 07:57:21 +0100
commita8d4731456ac3da0a70399e4ab821a763a4c04fb (patch)
tree1ccd0cad36cd091e3da92984b65ba90de6a5e266
parent93f0e1957372029262d728f01120d41869f0521a (diff)
Use _NSGetEnviron on OS X: fixes #2458
-rw-r--r--System/Posix/Env.hsc14
1 files changed, 13 insertions, 1 deletions
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.