From 12799d0fc7dcff0dc95640b1efad0637ad011144 Mon Sep 17 00:00:00 2001 From: Herbert Valerio Riedel <hvr@gnu.org> Date: Sun, 31 Jan 2016 16:54:04 +0100 Subject: [PATCH] Have Autoconf test for _NSGetEnviron presence --- System/Posix/Env.hsc | 6 ++---- System/Posix/Env/ByteString.hsc | 4 ++-- configure.ac | 4 ++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/System/Posix/Env.hsc b/System/Posix/Env.hsc index 6412bae..7d5f04c 100644 --- a/System/Posix/Env.hsc +++ b/System/Posix/Env.hsc @@ -78,9 +78,8 @@ 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. +#if HAVE__NSGETENVIRON +-- You should not access @char **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 @@ -88,7 +87,6 @@ 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 diff --git a/System/Posix/Env/ByteString.hsc b/System/Posix/Env/ByteString.hsc index 57b03aa..c6c374c 100644 --- a/System/Posix/Env/ByteString.hsc +++ b/System/Posix/Env/ByteString.hsc @@ -69,8 +69,8 @@ getEnvironmentPrim = do mapM B.packCString arr getCEnviron :: IO (Ptr CString) -#if darwin_HOST_OS --- You should not access _environ directly on Darwin in a bundle/shared library. +#if HAVE__NSGETENVIRON +-- You should not access @char **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 diff --git a/configure.ac b/configure.ac index 5b6eb7c..fdc27e4 100644 --- a/configure.ac +++ b/configure.ac @@ -40,6 +40,10 @@ AC_CHECK_FUNCS([readdir_r]) dnl not available on android so check for it AC_CHECK_FUNCS([telldir seekdir]) +dnl When available, _NSGetEnviron() (defined in <crt_externs.h>) is +dnl the preferred way to access environ(7) +AC_CHECK_FUNCS([_NSGetEnviron]) + dnl This is e.g. available as a GNU extension in glibc 2.11+ AC_CHECK_DECLS([execvpe]) AC_CHECK_FUNCS([execvpe]) -- GitLab