1 /* Copyright (C) 1992, 1995-2002, 2005-2011 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
20 optimizes away the name == NULL test below. */
21 #define _GL_ARG_NONNULL(params)
28 # define __set_errno(ev) ((errno) = (ev))
35 # define __environ environ
39 /* This lock protects against simultaneous modifications of `environ'. */
40 # include <bits/libc-lock.h>
41 __libc_lock_define_initialized (static, envlock)
42 # define LOCK __libc_lock_lock (envlock)
43 # define UNLOCK __libc_lock_unlock (envlock)
49 /* In the GNU C library we must keep the namespace clean. */
51 # define unsetenv __unsetenv
54 #if _LIBC || !HAVE_UNSETENV
57 unsetenv (const char *name)
62 if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
74 if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
76 /* Found it. Remove this pointer by moving later ones back. */
82 /* Continue the loop in case NAME appears again. */
94 weak_alias (__unsetenv, unsetenv)
97 #else /* HAVE_UNSETENV */
101 /* Call the underlying unsetenv, in case there is hidden bookkeeping
102 that needs updating beyond just modifying environ. */
104 rpl_unsetenv (const char *name)
107 if (!name || !*name || strchr (name, '='))
112 while (getenv (name))
120 #endif /* HAVE_UNSETENV */