diff options
author | Jim Meyering <jim@meyering.net> | 2003-05-04 08:30:01 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-05-04 08:30:01 +0000 |
commit | 6754f257e0ebaf819a90d39a98d640eeee5ee82e (patch) | |
tree | f635531cd50e86d91aac34e95ca37b66e51838d4 | |
parent | 986b5eca57e704fb43d7377445985997e71f329a (diff) | |
download | coreutils-6754f257e0ebaf819a90d39a98d640eeee5ee82e.tar.xz |
(__set_errno, LOCK, UNLOCK): Define.
(unsetenv): Update from GNU libc.
Ifdef-out this function, since the only caller
is putenv.c and that file now has its own copy.
-rw-r--r-- | lib/setenv.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/lib/setenv.c b/lib/setenv.c index 3ed901b7c..c09a62d5f 100644 --- a/lib/setenv.c +++ b/lib/setenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992, 1995, 2000 Free Software Foundation, Inc. +/* Copyright (C) 1992, 1995, 2000, 2003 Free Software Foundation, Inc. NOTE: The canonical source of this file is maintained with the GNU C Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. @@ -23,6 +23,12 @@ USA. */ #endif #include <errno.h> +#if !_LIBC +# if !defined errno +extern int errno; +# endif +# define __set_errno(ev) ((errno) = (ev)) +#endif #if _LIBC || HAVE_STDLIB_H # include <stdlib.h> @@ -38,6 +44,17 @@ USA. */ # define __environ environ #endif +#if _LIBC +/* This lock protects against simultaneous modifications of `environ'. */ +# include <bits/libc-lock.h> +__libc_lock_define_initialized (static, envlock) +# define LOCK __libc_lock_lock (envlock) +# define UNLOCK __libc_lock_unlock (envlock) +#else +# define LOCK +# define UNLOCK +#endif + int setenv (name, value, replace) const char *name; @@ -109,21 +126,46 @@ setenv (name, value, replace) return 0; } -void +/* WARNING: This function is not used by setenv-related code. + But it *is* used by putenv.c, so elide the code below. + Instead, use the static copy of the function that's in putenv.c. */ +#if 0 + +int unsetenv (name) const char *name; { - const size_t len = strlen (name); + size_t len; char **ep; - for (ep = __environ; *ep; ++ep) + if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) + { + __set_errno (EINVAL); + return -1; + } + + len = strlen (name); + + LOCK; + + ep = __environ; + while (*ep != NULL) if (!strncmp (*ep, name, len) && (*ep)[len] == '=') { /* Found it. Remove this pointer by moving later ones back. */ char **dp = ep; + do dp[0] = dp[1]; while (*dp++); /* Continue the loop in case NAME appears again. */ } + else + ++ep; + + UNLOCK; + + return 0; } + +#endif |