1 /* Copyright (C) 1991, 2000, 2001 Free Software Foundation, Inc.
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
19 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
22 #include "libguile/scmconfig.h"
25 #include <sys/types.h>
28 /* Don't include stdlib.h for non-GNU C libraries because some of them
29 contain conflicting prototypes for getopt.
30 This needs to come after some library #include
31 to get __GNU_LIBRARY__ defined. */
32 #ifdef __GNU_LIBRARY__
36 #endif /* GNU C library. */
38 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
46 #define memcpy(d, s, n) bcopy((s), (d), (n))
58 extern char **environ
;
60 /* Put STRING, which is of the form "NAME=VALUE", in the environment. */
62 putenv (const char *string
)
64 char *name_end
= strchr (string
, '=');
70 /* Remove the variable from the environment. */
71 size
= strlen (string
);
72 for (ep
= environ
; *ep
!= NULL
; ++ep
)
73 if (!strncmp (*ep
, string
, size
) && (*ep
)[size
] == '=')
86 for (ep
= environ
; *ep
!= NULL
; ++ep
)
87 if (!strncmp (*ep
, string
, name_end
- string
) &&
88 (*ep
)[name_end
- string
] == '=')
95 static char **last_environ
= NULL
;
96 char **new_environ
= (char **) malloc ((size
+ 2) * sizeof (char *));
97 if (new_environ
== NULL
)
99 memcpy ((char *) new_environ
, (char *) environ
, size
* sizeof (char *));
100 new_environ
[size
] = (char *) string
;
101 new_environ
[size
+ 1] = NULL
;
102 if (last_environ
!= NULL
)
103 free ((char *) last_environ
);
104 last_environ
= new_environ
;
105 environ
= new_environ
;
108 *ep
= (char *) string
;