aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/Env.hsc
diff options
context:
space:
mode:
authorGravatar Paolo Capriotti <p.capriotti@gmail.com>2012-04-04 15:33:53 +0100
committerGravatar Paolo Capriotti <p.capriotti@gmail.com>2012-04-04 17:34:10 +0100
commita0379db01dce6b4371ead2ce82e4221e1ae8c334 (patch)
tree4c831f14340e1c554b9f15696f72aa1ffad90419 /System/Posix/Env.hsc
parent5ee7433f9fbe1cf1ea825eaf5943edff0f9bd7b3 (diff)
Add workaround for systems without clearenv.
Diffstat (limited to 'System/Posix/Env.hsc')
-rw-r--r--System/Posix/Env.hsc11
1 files changed, 10 insertions, 1 deletions
diff --git a/System/Posix/Env.hsc b/System/Posix/Env.hsc
index 51e8891..be4711b 100644
--- a/System/Posix/Env.hsc
+++ b/System/Posix/Env.hsc
@@ -36,7 +36,7 @@ import Foreign.C.String
import Foreign.Marshal.Array
import Foreign.Ptr
import Foreign.Storable
-import Control.Monad (liftM, forM_, void)
+import Control.Monad
import Data.Maybe (fromMaybe)
#if __GLASGOW_HASKELL__ > 700
import System.Posix.Internals (withFilePath, peekFilePath)
@@ -83,6 +83,7 @@ getEnvironmentPrim = do
mapM peekFilePath 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
@@ -170,7 +171,15 @@ setEnv key value False = do
-- |The 'clearEnv' function clears the environment of all name-value pairs.
clearEnv :: IO ()
+#if HAVE_CLEARENV
clearEnv = void c_clearenv
foreign import ccall unsafe "clearenv"
c_clearenv :: IO Int
+#else
+-- Fallback to 'environ[0] = NULL'.
+clearEnv = do
+ c_environ <- getCEnviron
+ unless (c_environ == nullPtr) $
+ poke c_environ nullPtr
+#endif