-/* Copyright (C) 1991, 2000 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
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA */
-
-/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
- gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
+/* Copyright (C) 1991, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
+
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
-#ifdef HAVE_CONFIG_H
#include "libguile/scmconfig.h"
-#endif
#include <sys/types.h>
#include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt.
#include <unistd.h>
#endif
+#if HAVE_CRT_EXTERNS_H
+#include <crt_externs.h> /* 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)
if (*ep == NULL)
{
static char **last_environ = NULL;
- char **new_environ = (char **) malloc ((size + 2) * sizeof (char *));
- if (new_environ == NULL)
- return -1;
+ char **new_environ = (char **) scm_malloc ((size + 2) * sizeof (char *));
memcpy ((char *) new_environ, (char *) environ, size * sizeof (char *));
new_environ[size] = (char *) string;
new_environ[size + 1] = NULL;