<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From 94aa3b6b43cccdda370ebbef6b2e6fd603c3d922 Mon Sep 17 00:00:00 2001
From: Klemens Morgenstern &lt;klemens.morgenstern@gmx.net&gt;
Date: Thu, 27 Feb 2025 10:13:22 +0800
Subject: [PATCH] fixed environ for OSX

closes #453
---
 .../boost/process/v1/detail/posix/environment.hpp    |  4 ++--
 include/boost/process/v1/detail/posix/executor.hpp   |  4 ++--
 include/boost/process/v1/extend.hpp                  |  2 +-
 .../boost/process/v2/detail/environment_posix.hpp    |  9 +++++++--
 include/boost/process/v2/posix/default_launcher.hpp  | 12 ++++++++----
 src/detail/environment_posix.cpp                     |  2 +-
 6 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/include/boost/process/v1/detail/posix/environment.hpp b/include/boost/process/v1/detail/posix/environment.hpp
index 6ddfc559c..64bb63556 100644
--- boost/process/v1/detail/posix/environment.hpp
+++ boost/process/v1/detail/posix/environment.hpp
@@ -107,7 +107,7 @@ class native_environment_impl&lt;char&gt;
     using string_type = std::basic_string&lt;char_type&gt;;
     using native_handle_type = char_type **;
 
-    void reload() {this-&gt;_env_impl = ::environ;}
+    void reload() {this-&gt;_env_impl = environ;}
 
     string_type get(const pointer_type id) { return getenv(id); }
     void        set(const pointer_type id, const pointer_type value)
@@ -136,7 +136,7 @@ class native_environment_impl&lt;char&gt;
     native_environment_impl &amp; operator=(native_environment_impl &amp;&amp; ) = default;
     native_handle_type _env_impl = environ;
 
-    native_handle_type native_handle() const {return ::environ;}
+    native_handle_type native_handle() const {return environ;}
 };
 
 
diff --git a/include/boost/process/v1/detail/posix/executor.hpp b/include/boost/process/v1/detail/posix/executor.hpp
index cc1bcb6cf..b462e41d4 100644
--- boost/process/v1/detail/posix/executor.hpp
+++ boost/process/v1/detail/posix/executor.hpp
@@ -275,7 +275,7 @@ class executor
         prepare_cmd_style_fn = exe;
         if ((prepare_cmd_style_fn.find('/') == std::string::npos) &amp;&amp; ::access(prepare_cmd_style_fn.c_str(), X_OK))
         {
-            const auto * e = ::environ;
+            const auto * e = environ;
             while ((e != nullptr) &amp;&amp; (*e != nullptr) &amp;&amp; !boost::starts_with(*e, "PATH="))
                 e++;
 
@@ -316,7 +316,7 @@ class executor
     const char * exe      = nullptr;
     char *const* cmd_line = nullptr;
     bool cmd_style = false;
-    char **env      = ::environ;
+    char **env      = environ;
     pid_t pid = -1;
     std::shared_ptr&lt;std::atomic&lt;int&gt;&gt; exit_status = std::make_shared&lt;std::atomic&lt;int&gt;&gt;(still_active);
 
diff --git a/include/boost/process/v1/extend.hpp b/include/boost/process/v1/extend.hpp
index 185972225..cb7b05c79 100644
--- boost/process/v1/extend.hpp
+++ boost/process/v1/extend.hpp
@@ -249,7 +249,7 @@ struct posix_executor
      ///A pointer to the argument-vector.
      char *const* cmd_line = nullptr;
      ///A pointer to the environment variables, as default it is set to [environ](http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html)
-     char **env      = ::environ;
+     char **env      = environ;
      ///The pid of the process - it will be -1 before invoking [fork](http://pubs.opengroup.org/onlinepubs/009695399/functions/fork.html), and after forking either 0 for the new process or a positive value if in the current process. */
      pid_t pid = -1;
      ///This shared-pointer holds the exit code. It's done this way, so it can be shared between an `asio::io_context` and \ref child.
diff --git a/include/boost/process/v2/detail/environment_posix.hpp b/include/boost/process/v2/detail/environment_posix.hpp
index 756432d66..becd9f3e8 100644
--- boost/process/v2/detail/environment_posix.hpp
+++ boost/process/v2/detail/environment_posix.hpp
@@ -14,8 +14,13 @@
 #include &lt;boost/process/v2/detail/config.hpp&gt;
 #include &lt;boost/process/v2/cstring_ref.hpp&gt;
 
-#if defined(__APPLE__) || defined(__MACH__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun)
-extern "C" { extern char **environ; }
+#if defined(__APPLE__)
+# include &lt;crt_externs.h&gt;
+# if !defined(environ)
+#  define environ (*_NSGetEnviron())
+# endif
+#elif defined(__MACH__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun)
+ extern "C" { extern char **environ; }
 #endif
 
 BOOST_PROCESS_V2_BEGIN_NAMESPACE
diff --git a/include/boost/process/v2/posix/default_launcher.hpp b/include/boost/process/v2/posix/default_launcher.hpp
index d17bda5e7..fc826fea2 100644
--- boost/process/v2/posix/default_launcher.hpp
+++ boost/process/v2/posix/default_launcher.hpp
@@ -30,9 +30,13 @@
 #include &lt;sys/wait.h&gt;
 #include &lt;unistd.h&gt;
 
-
-#if defined(__APPLE__) || defined(__MACH__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun)
-extern "C" { extern char **environ; }
+#if defined(__APPLE__)
+# include &lt;crt_externs.h&gt;
+# if !defined(environ)
+#  define environ (*_NSGetEnviron())
+# endif
+#elif defined(__MACH__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun)
+ extern "C" { extern char **environ; }
 #endif
 
 BOOST_PROCESS_V2_BEGIN_NAMESPACE
@@ -260,7 +264,7 @@ inline void on_exec_error(Launcher &amp; launcher, const filesystem::path &amp;executabl
 struct default_launcher
 {
     /// The pointer to the environment forwarded to the subprocess.
-    const char * const * env = ::environ;
+    const char * const * env = environ;
     /// The pid of the subprocess - will be assigned after fork.
     int pid = -1;
 
diff --git a/src/detail/environment_posix.cpp b/src/detail/environment_posix.cpp
index 7a7913671..5c2f81260 100644
--- libs/process/src/detail/environment_posix.cpp
+++ libs/process/src/detail/environment_posix.cpp
@@ -51,7 +51,7 @@ void unset(basic_cstring_ref&lt;char_type, key_char_traits&lt;char_type&gt;&gt; key, error_c
 }
 
 
-native_handle_type load_native_handle() { return ::environ; }
+native_handle_type load_native_handle() { return environ; }
 
 
 native_iterator next(native_iterator nh)
</pre></body></html>