From 53773207f40adb94ad60a34840a4d252e5a839a5 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 18 Jun 2010 10:32:57 +0100 Subject: [PATCH] fix environ on MAC --- library/system/sys.c | 18 +++++++++--------- packages/clib/unix.c | 4 ++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/library/system/sys.c b/library/system/sys.c index 5334e7fae..3bbfb98ad 100644 --- a/library/system/sys.c +++ b/library/system/sys.c @@ -539,28 +539,28 @@ p_tmpdir(void) static int p_environ(void) { -#if HAVE_ENVIRON -#if defined(__MINGW32__) || _MSC_VER +#if HAVE_ENVIRON && 0 +#if HAVE__NSGETENVIRON + char ** ptr = _NSGetEnviron(); +#elif defined(__MINGW32__) || _MSC_VER extern char **_environ; + char ** ptr = _environ; #else extern char **environ; + char ** ptr = environ; #endif YAP_Term t1 = YAP_ARG1; long int i; i = YAP_IntOfTerm(t1); -#if defined(__MINGW32__) || _MSC_VER - if (_environ[i] == NULL) -#else - if (environ[i] == NULL) -#endif + if (ptr[i] == NULL) return(FALSE); else { - YAP_Term t = YAP_BufferToString(environ[i]); + YAP_Term t = YAP_BufferToString(ptr[i]); return(YAP_Unify(t, YAP_ARG2)); } #else - YAP_Error(0,0L,"environ not available in this configuration"); + YAP_Error(0, 0L, "environ not available in this configuration" ); return(FALSE); #endif } diff --git a/packages/clib/unix.c b/packages/clib/unix.c index 348cb4618..e2d4cfad0 100644 --- a/packages/clib/unix.c +++ b/packages/clib/unix.c @@ -247,7 +247,11 @@ pl_environ(term_t l) term_t vt = PL_new_term_ref(); functor_t FUNCTOR_equal2 = PL_new_functor(PL_new_atom("="), 2); +#if HAVE__NSGETENVIRON + for(e = _NSGetEnviron(); *e; e++) +#else for(e = environ; *e; e++) +#endif { char *s = strchr(*e, '='); if ( !s )