1 /* Copyright (C) 1991, 1994 Free Software Foundation, Inc.
4 NOTE: The canonical source of this file is maintained with the GNU C Library.
5 Bugs can be reported to bug-glibc@prep.ai.mit.edu.
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 /* Define-away any (possibly conflicting) prototype of putenv.
28 Many systems omit the `const' attribute on the argument. */
29 #define putenv _sys_putenv
31 #if defined (__GNU_LIBRARY__) || defined (HAVE_STDLIB_H)
34 #if defined (__GNU_LIBRARY__) || defined (HAVE_STRING_H)
37 #if defined (__GNU_LIBRARY__) || defined (HAVE_UNISTD_H)
43 #if !defined (__GNU_LIBRARY__) && !defined (HAVE_STRCHR)
46 #if !defined (__GNU_LIBRARY__) && !defined (HAVE_MEMCPY)
47 #define memcpy(d,s,n) bcopy ((s), (d), (n))
51 #define environ __environ
53 extern char **environ
;
57 /* Put STRING, which is of the form "NAME=VALUE", in the environment. */
62 const char *const name_end
= strchr (string
, '=');
68 /* Remove the variable from the environment. */
69 size
= strlen (string
);
70 for (ep
= environ
; *ep
!= NULL
; ++ep
)
71 if (!strncmp (*ep
, string
, size
) && (*ep
)[size
] == '=')
84 for (ep
= environ
; *ep
!= NULL
; ++ep
)
85 if (!strncmp (*ep
, string
, name_end
- string
) &&
86 (*ep
)[name_end
- string
] == '=')
93 static char **last_environ
= NULL
;
94 char **new_environ
= (char **) malloc ((size
+ 2) * sizeof (char *));
95 if (new_environ
== NULL
)
97 (void) memcpy ((void *) new_environ
, (void *) environ
,
98 size
* sizeof (char *));
99 new_environ
[size
] = (char *) string
;
100 new_environ
[size
+ 1] = NULL
;
101 if (last_environ
!= NULL
)
102 free ((void *) last_environ
);
103 last_environ
= new_environ
;
104 environ
= new_environ
;
107 *ep
= (char *) string
;