From efb7b9dec135594718b765234bc1f745855f60d2 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Tue, 14 Feb 2012 12:21:03 +0100 Subject: Use _NSGetEnviron() instead of environ where required OS X would otherwise crash with a segfault when linked statically to some libraries. --- src/common/compat.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/common/compat.c') diff --git a/src/common/compat.c b/src/common/compat.c index 64c06681da..f25a8ac3b0 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -51,6 +51,9 @@ #ifdef HAVE_ARPA_INET_H #include #endif +#ifdef HAVE_CRT_EXTERNS_H +#include +#endif #ifndef HAVE_GETTIMEOFDAY #ifdef HAVE_FTIME @@ -1659,6 +1662,26 @@ make_path_absolute(char *fname) #endif } +#ifndef HAVE__NSGETENVIRON +/* FreeBSD needs this; it doesn't seem to hurt other platforms. */ +extern char **environ; +#endif + +/** Return the current environment. This is a portable replacement for + * 'environ'. */ +char ** +get_environment(void) +{ +#ifdef HAVE__NSGETENVIRON + /* This is for compatibility between OSX versions. Otherwise (for example) + * when we do a mostly-static build on OSX 10.7, the resulting binary won't + * work on OSX 10.6. */ + return *_NSGetEnviron(); +#else + return environ; +#endif +} + /** Set *addr to the IP address (in dotted-quad notation) stored in c. * Return 1 on success, 0 if c is badly formatted. (Like inet_aton(c,addr), * but works on Windows and Solaris.) -- cgit v1.2.3-54-g00ecf