cdc05dd7e737c931874fc1fdc647618b6111792b
1 /* Copyright (C) 1991, 2000, 2001, 2004, 2005, 2006 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "libguile/scmconfig.h"
26 #include <sys/types.h>
29 /* Don't include stdlib.h for non-GNU C libraries because some of them
30 contain conflicting prototypes for getopt.
31 This needs to come after some library #include
32 to get __GNU_LIBRARY__ defined. */
33 #ifdef __GNU_LIBRARY__
37 #endif /* GNU C library. */
39 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
47 #define memcpy(d, s, n) bcopy((s), (d), (n))
55 #if HAVE_CRT_EXTERNS_H
56 #include <crt_externs.h> /* for Darwin _NSGetEnviron */
63 extern char **environ
;
65 /* On Apple Darwin in a shared library there's no "environ" to access
66 directly, instead the address of that variable must be obtained with
68 #if HAVE__NSGETENVIRON && defined (PIC)
69 #define environ (*_NSGetEnviron())
72 /* Put STRING, which is of the form "NAME=VALUE", in the environment. */
74 putenv (const char *string
)
76 char *name_end
= strchr (string
, '=');
82 /* Remove the variable from the environment. */
83 size
= strlen (string
);
84 for (ep
= environ
; *ep
!= NULL
; ++ep
)
85 if (!strncmp (*ep
, string
, size
) && (*ep
)[size
] == '=')
98 for (ep
= environ
; *ep
!= NULL
; ++ep
)
99 if (!strncmp (*ep
, string
, name_end
- string
) &&
100 (*ep
)[name_end
- string
] == '=')
107 static char **last_environ
= NULL
;
108 char **new_environ
= (char **) scm_malloc ((size
+ 2) * sizeof (char *));
109 memcpy ((char *) new_environ
, (char *) environ
, size
* sizeof (char *));
110 new_environ
[size
] = (char *) string
;
111 new_environ
[size
+ 1] = NULL
;
112 if (last_environ
!= NULL
)
113 free ((char *) last_environ
);
114 last_environ
= new_environ
;
115 environ
= new_environ
;
118 *ep
= (char *) string
;