diff --git a/libguile/posix.c b/libguile/posix.c index 7b18024ad..9589526fc 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -159,6 +159,10 @@ extern char ** environ; # include #endif +#if HAVE_CRT_EXTERNS_H +#include /* for Darwin _NSGetEnviron */ +#endif + /* Some Unix systems don't define these. CPP hair is dangerous, but this seems safe enough... */ #ifndef R_OK @@ -196,6 +200,13 @@ extern char ** environ; above means that _POSIX_SOURCE may be #defined, which will encourage header files to do strange things. */ +/* On Apple Darwin in a shared library there's no "environ" to access + directly, instead the address of that variable must be obtained with + _NSGetEnviron(). */ +#if HAVE__NSGETENVIRON && defined (PIC) +#define environ (*_NSGetEnviron()) +#endif + SCM_SYMBOL (sym_read_pipe, "read pipe"); SCM_SYMBOL (sym_write_pipe, "write pipe"); diff --git a/libguile/putenv.c b/libguile/putenv.c index ccfaaa2d8..32973bcdc 100644 --- a/libguile/putenv.c +++ b/libguile/putenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 2000, 2001 Free Software Foundation, Inc. +/* Copyright (C) 1991, 2000, 2001, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -73,12 +73,23 @@ char *malloc (); #include #endif +#if HAVE_CRT_EXTERNS_H +#include /* for Darwin _NSGetEnviron */ +#endif + #ifndef NULL #define NULL 0 #endif extern char **environ; +/* On Apple Darwin in a shared library there's no "environ" to access + directly, instead the address of that variable must be obtained with + _NSGetEnviron(). */ +#if HAVE__NSGETENVIRON && defined (PIC) +#define environ (*_NSGetEnviron()) +#endif + /* Put STRING, which is of the form "NAME=VALUE", in the environment. */ int putenv (const char *string) diff --git a/libguile/stime.c b/libguile/stime.c index 3df809215..c6136c4ef 100644 --- a/libguile/stime.c +++ b/libguile/stime.c @@ -87,6 +87,10 @@ # include #endif +#if HAVE_CRT_EXTERNS_H +#include /* for Darwin _NSGetEnviron */ +#endif + #ifndef tzname /* For SGI. */ extern char *tzname[]; /* RS6000 and others reject char **tzname. */ #endif @@ -112,6 +116,15 @@ extern char *strptime (); # define timet long #endif +extern char ** environ; + +/* On Apple Darwin in a shared library there's no "environ" to access + directly, instead the address of that variable must be obtained with + _NSGetEnviron(). */ +#if HAVE__NSGETENVIRON && defined (PIC) +#define environ (*_NSGetEnviron()) +#endif + #ifdef HAVE_TIMES static timet mytime() @@ -294,7 +307,6 @@ filltime (struct tm *bd_time, int zoff, char *zname) } static char tzvar[3] = "TZ"; -extern char ** environ; /* if zone is set, create a temporary environment with only a TZ string. other threads or interrupt handlers shouldn't be allowed