1 /* Copyright (C) 1992, 1995-2002, 2005-2017 Free Software Foundation,
3 This file is part of the GNU C Library.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
19 optimizes away the name == NULL test below. */
20 #define _GL_ARG_NONNULL(params)
29 # define __set_errno(ev) ((errno) = (ev))
36 # define __environ environ
40 /* This lock protects against simultaneous modifications of 'environ'. */
41 # include <bits/libc-lock.h>
42 __libc_lock_define_initialized (static, envlock
)
43 # define LOCK __libc_lock_lock (envlock)
44 # define UNLOCK __libc_lock_unlock (envlock)
50 /* In the GNU C library we must keep the namespace clean. */
52 # define unsetenv __unsetenv
55 #if _LIBC || !HAVE_UNSETENV
58 unsetenv (const char *name
)
63 if (name
== NULL
|| *name
== '\0' || strchr (name
, '=') != NULL
)
75 if (!strncmp (*ep
, name
, len
) && (*ep
)[len
] == '=')
77 /* Found it. Remove this pointer by moving later ones back. */
83 /* Continue the loop in case NAME appears again. */
95 weak_alias (__unsetenv
, unsetenv
)
98 #else /* HAVE_UNSETENV */
101 # if !HAVE_DECL_UNSETENV
103 extern void unsetenv (const char *);
105 extern int unsetenv (const char *);
109 /* Call the underlying unsetenv, in case there is hidden bookkeeping
110 that needs updating beyond just modifying environ. */
112 rpl_unsetenv (const char *name
)
115 if (!name
|| !*name
|| strchr (name
, '='))
120 while (getenv (name
))
128 #endif /* HAVE_UNSETENV */