[commit: unix] master, encoding: Use _NSGetEnviron on OS X: fixes #2458 (a8d4731)
Ian Lynagh
igloo at earth.li
Fri Apr 8 13:42:45 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/packages/unix
On branches: master,encoding
http://hackage.haskell.org/trac/ghc/changeset/a8d4731456ac3da0a70399e4ab821a763a4c04fb
>---------------------------------------------------------------
commit a8d4731456ac3da0a70399e4ab821a763a4c04fb
Author: Max Bolingbroke <batterseapower at hotmail.com>
Date: Wed Apr 6 07:57:21 2011 +0100
Use _NSGetEnviron on OS X: fixes #2458
>---------------------------------------------------------------
System/Posix/Env.hsc | 14 +++++++++++++-
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.
More information about the Cvs-libraries
mailing list