Mercurial > hg > octave-nkf > gnulib-hg
view lib/putenv.c @ 6275:fd0ccce602e4
Sync from coreutils.
* .cppi-disable: Add regcomp.c, regex_internal.c, regex_internal.h,
stat-time.h.
* argmatch.h: Include verify.h
(ARGMATCH_VERIFY): Use verify rather than rolling our own.
(ARGMATCH_ASSERT): Remove; unused.
* canonicalize.c: Assume STDC_HEADERS.
* exclude.c: Include "strcase.h".
* regex_internal.h [!defined _LIBC]: Likewise.
* getusershell.c: Include stdio--.h rather than stdio.h
and stdio-safer.h.
(getusershell): Call fopen, not fopen_safer.
* save-cwd.c: Include fcntl--.h rather than fcntl.h.
Do not include unistd-safer.h.
(save_cwd): Don't call fd_safer; no longer needed
now that we include fcntl--.h.
* modules/argmatch (Depends-on): Add verify.
* modules/getloadavg (Depends-on): Depend on fcntl-safer, not
unistd-safer.
* modules/save-cwd (Depends-on): Likewise.
* backupfile.m4, calloc.m4, chown.m4, cloexec.m4, dup2.m4:
* fileblocks.m4, free.m4, ftruncate.m4, getcwd.m4, getpagesize.m4:
* getugroups.m4, group-member.m4, idcache.m4, link-follow.m4:
* mkstemp.m4, mktime.m4, mountlist.m4, nanosleep.m4, pathmax.m4:
* physmem.m4, posixver.m4, putenv.m4, safe-read.m4, same.m4:
* save-cwd.m4, stdio-safer.m4, unistd-safer.m4, unlinkdir.m4:
* userspec.m4, xgetcwd.m4, xreadlink.m4:
Don't bother checking for string.h, stdlib.h, unistd.h.
* fts.m4 (gl_FUNC_FTS_CORE): Don't require
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK; that's now the lstat
module's job.
* jm-macros.m4 (gl_MACROS): Likewise.
* prereq.m4 (gl_PREREQ): Add gl_FUNC_LSTAT.
* backupfile.c: Use ARGMATCH_VERIFY, just in case.
* posixtm.c (posixtime) [lint]: Initialize *all* of tm0, not just
the .tm_year member, since otherwise gcc-4.0 would now warn about
tm_zone, tm_gmtoff, tm_isdst, tm_yday, tm_wday.
* quotearg.c (quotearg_n_options): Change code to be suboptimal, in
order to avoid an unsuppressible warning from gcc on 64-bit systems.
* lstat.m4 (gl_FUNC_LSTAT):
Use AC_LIBSOURCES to require lstat.c and lstat.h.
Remove obsolete comment.
* xreadlink.m4: Use AC_LIBSOURCES and AC_LIBOBJ.
* xstrtod.m4: Likewise.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Fri, 23 Sep 2005 04:15:13 +0000 |
parents | 96c32553b4c6 |
children | 8a1a9361108c |
line wrap: on
line source
/* Copyright (C) 1991, 1994, 1997, 1998, 2000, 2003, 2004, 2005 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. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include <config.h> #endif #include <stddef.h> /* Include errno.h *after* sys/types.h to work around header problems on AIX 3.2.5. */ #include <errno.h> #ifndef __set_errno # define __set_errno(ev) ((errno) = (ev)) #endif /* Don't include stdlib.h because some (e.g., Solaris 7) declare putenv with a non-const argument. That would conflict with the declaration of rpl_putenv below (due to the #define putenv rpl_putenv from config.h). */ void *malloc (); void free (); #include <string.h> #include <unistd.h> #if HAVE_GNU_LD # define environ __environ #else extern char **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 static int unsetenv (const char *name) { size_t len; char **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; } /* Put STRING, which is of the form "NAME=VALUE", in the environment. If STRING contains no `=', then remove STRING from the environment. */ int rpl_putenv (const char *string) { const char *const name_end = strchr (string, '='); register size_t size; register char **ep; if (name_end == NULL) { /* Remove the variable from the environment. */ return unsetenv (string); } size = 0; for (ep = environ; *ep != NULL; ++ep) if (!strncmp (*ep, string, name_end - string) && (*ep)[name_end - string] == '=') break; else ++size; if (*ep == NULL) { static char **last_environ = NULL; char **new_environ = (char **) malloc ((size + 2) * sizeof (char *)); if (new_environ == NULL) return -1; (void) memcpy ((void *) new_environ, (void *) environ, size * sizeof (char *)); new_environ[size] = (char *) string; new_environ[size + 1] = NULL; if (last_environ != NULL) free (last_environ); last_environ = new_environ; environ = new_environ; } else *ep = (char *) string; return 0; }