diff options
author | Paolo Capriotti <p.capriotti@gmail.com> | 2012-04-04 15:33:53 +0100 |
---|---|---|
committer | Paolo Capriotti <p.capriotti@gmail.com> | 2012-04-04 17:34:10 +0100 |
commit | a0379db01dce6b4371ead2ce82e4221e1ae8c334 (patch) | |
tree | 4c831f14340e1c554b9f15696f72aa1ffad90419 | |
parent | 5ee7433f9fbe1cf1ea825eaf5943edff0f9bd7b3 (diff) |
Add workaround for systems without clearenv.
-rw-r--r-- | System/Posix/Env.hsc | 11 | ||||
-rw-r--r-- | configure.ac | 2 |
2 files changed, 11 insertions, 2 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 diff --git a/configure.ac b/configure.ac index 775af6c..ebf708d 100644 --- a/configure.ac +++ b/configure.ac @@ -28,7 +28,7 @@ AC_CHECK_HEADERS([termios.h time.h unistd.h utime.h]) AC_CHECK_FUNCS([getgrgid_r getgrnam_r getpwnam_r getpwuid_r getpwnam getpwuid]) AC_CHECK_FUNCS([getpwent getgrent]) -AC_CHECK_FUNCS([lchown setenv sysconf unsetenv]) +AC_CHECK_FUNCS([lchown setenv sysconf unsetenv clearenv]) AC_CHECK_FUNCS([nanosleep]) AC_CHECK_FUNCS([ptsname]) AC_CHECK_FUNCS([setitimer]) |