char ** enivron is inconsistent on some platforms
authorMichael Lee <mzlee@fb.com>
Sun, 29 Jan 2017 03:43:50 +0000 (19:43 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sun, 29 Jan 2017 03:47:51 +0000 (19:47 -0800)
Summary: The forward declaration of `extern char ** environ` is inconsistent on some platforms.

Reviewed By: strager, Orvid

Differential Revision: D4474856

fbshipit-source-id: c73a7c7d5a247e962fab06aeb65df7815f0e3bcb

folly/portability/Stdlib.h

index 3aca93bfbc53d444c74867e0353814c5a925a6ef..9b16d7607c66368d540c669d2935a7c5c9235d95 100644 (file)
 
 #include <cstdlib>
 
+#if defined(__APPLE__)
+#include <TargetConditionals.h>
+#if (TARGET_OS_OSX || TARGET_OS_SIMULATOR)
+#include <crt_extern.h>
+#endif
+#endif
+
 extern "C" {
 #ifdef _WIN32
 // These are technically supposed to be defined linux/limits.h and
@@ -34,7 +41,7 @@ int mkstemp(char* tn);
 char* realpath(const char* path, char* resolved_path);
 int setenv(const char* name, const char* value, int overwrite);
 int unsetenv(const char* name);
-#else
-extern char** environ;
+#elif defined(__APPLE__) && (TARGET_OS_OSX || TARGET_OS_SIMULATOR)
+#define environ (*_NSGetEnviron())
 #endif
 }