-
-
Save shirok/46a52b108d2b7dae6094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/configure.ac b/configure.ac | |
index 6d7550b..9078aa3 100644 | |
--- a/configure.ac | |
+++ b/configure.ac | |
@@ -347,6 +347,10 @@ AC_CHECK_HEADERS(pty.h util.h libutil.h sys/loadavg.h sys/resource.h) | |
dnl solaris specific | |
AC_CHECK_HEADERS(sunmath.h) | |
+dnl OSX specific. If this header exists, we assume that extern char **environ | |
+dnl isn't available and we should use _NSGetEnviron(). | |
+AC_CHECK_HEADERS(crt_externs.h) | |
+ | |
dnl =========================================================== | |
dnl Checks processor type, for processor-specific stuff | |
case $host in | |
diff --git a/src/gauche/config.h.in b/src/gauche/config.h.in | |
index 60ea11f..4b442fd 100644 | |
--- a/src/gauche/config.h.in | |
+++ b/src/gauche/config.h.in | |
@@ -92,6 +92,9 @@ | |
/* Define to 1 if the system has clearenv */ | |
#undef HAVE_CLEARENV | |
+/* Define to 1 if the system has crt_extern.h */ | |
+#undef HAVE_CRT_EXTERNS_H | |
+ | |
/* Define if uses libcrypt */ | |
#undef HAVE_CRYPT | |
diff --git a/src/system.c b/src/system.c | |
index 50b910c..88334cb 100644 | |
--- a/src/system.c | |
+++ b/src/system.c | |
@@ -62,9 +62,16 @@ | |
#include <pwd.h> | |
#include <sys/times.h> | |
#include <sys/wait.h> | |
+ | |
+# if !defined(HAVE_CRT_EXTERNS_H) | |
/* POSIX defines environ, and ISO C defines __environ. | |
Modern C seems to have the latter declared in unistd.h */ | |
extern char **environ; | |
+# else /* HAVE_CRT_EXTERNS_H */ | |
+/* On newer OSX, we can't directly access global 'environ' variable. | |
+ We need to use _NSGetEnviron(), and this header defines it. */ | |
+#include <crt_externs.h> | |
+# endif /* HAVE_CRT_EXTERNS_H */ | |
#else /* GAUCHE_WINDOWS */ | |
#include <lm.h> | |
#include <tlhelp32.h> | |
@@ -2162,6 +2169,9 @@ void Scm_SetEnv(const char *name, const char *value, int overwrite) | |
ScmObj Scm_Environ(void) | |
{ | |
#if !defined(GAUCHE_WINDOWS) | |
+# if defined(HAVE_CRT_EXTERNS_H) | |
+ char **environ = *_NSGetEnviron(); /* OSX Hack */ | |
+# endif /*HAVE_CRT_EXTERNS_H*/ | |
if (environ == NULL) return SCM_NIL; | |
else return Scm_CStringArrayToList((const char**)environ, -1, | |
SCM_STRING_COPYING); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment