1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
19 #include <sys/types.h>
22 /* This needs to come after some library #include
23 to get __GNU_LIBRARY__ defined. */
24 #ifdef __GNU_LIBRARY__
25 /* Don't include stdlib.h for non-GNU C libraries because some of them
26 contain conflicting prototypes for getopt. */
28 #endif /* GNU C library. */
34 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
40 #define bcopy(s, d, n) memcpy((d), (s), (n))
54 extern char **environ;
56 /* Put STRING, which is of the form "NAME=VALUE", in the environment. */
61 char *name_end = index (string, '=');
67 /* Remove the variable from the environment. */
68 size = strlen (string);
69 for (ep = environ; *ep != NULL; ++ep)
70 if (!strncmp (*ep, string, size) && (*ep)[size] == '=')
83 for (ep = environ; *ep != NULL; ++ep)
84 if (!strncmp (*ep, string, name_end - string) &&
85 (*ep)[name_end - string] == '=')
92 static char **last_environ = NULL;
93 char **new_environ = (char **) malloc ((size + 2) * sizeof (char *));
94 if (new_environ == NULL)
96 (void) bcopy ((char *) environ, (char *) new_environ, size * sizeof (char *));
97 new_environ[size] = (char *) string;
98 new_environ[size + 1] = NULL;
99 if (last_environ != NULL)
100 free ((char *) last_environ);
101 last_environ = new_environ;
102 environ = new_environ;
105 *ep = (char *) string;