redjack/libcork — pull request #43 by dcreager (2013-03-07 14:45:53+00:00)
Title: clearenv replacement on Mac OS X and BSDs

Mac OS X, FreeBSD, OpenBSD, and NetBSD don't provide the `clearenv(3)` function, which we were using to clear out the current environment before replacing it with the contents of a `cork_env` instance. This patch adds replacement implementations on these platforms. On the BSDs, the replacement is simple; we just assign an empty array into the `extern` variable. On Mac OS X, however, we don't have access to `environ` in a shared library, and must use a [helper function](http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html) to get the pointer to the environment array.

Note that there are several other platforms that also don't provide `clearenv(3)` (see a [full list](http://www.gnu.org/software/gnulib/manual/html_node/clearenv.html)). At some point, we'll want to expand our preprocessor checks to provide the replacement implementation on those platforms, too. But I don't have instances of those platforms to test on, so I'm leaving them out for now.