Portability to AIX 4.3.3.

This commit is contained in:
Bruno Haible 2002-03-04 20:29:02 +00:00
parent 79d4e50cc3
commit 201ac6ddda
7 changed files with 134 additions and 49 deletions

View File

@ -1,3 +1,12 @@
2002-03-04 Bruno Haible <bruno@clisp.org>
Portability to AIX 4.3.3.
* unsetenv.c: New file, extracted from setenv.c.
* setenv.c: Move the unsetenv() function to unsetenv.c.
* setenv.h: Cope with systems that have setenv() but not unsetenv().
* Makefile.am (LIBADD_SOURCE): Add unsetenv.c.
(c-ctype.lo, tmpdir.lo): Depend on stdbool.h.
2002-02-21 Bruno Haible <bruno@clisp.org>
* strncasecmp.c (__strncasecmp): Trivial simplification.

View File

@ -68,7 +68,7 @@ LIBADD_SOURCE = \
memset.c \
mkdtemp.h mkdtemp.c \
pfnmatch.h pfnmatch.c \
setenv.h setenv.c \
setenv.h setenv.c unsetenv.c \
libstdarg.h \
stpcpy.h stpcpy.c \
stpncpy.h stpncpy.c \
@ -116,7 +116,7 @@ INCLUDES = -I. -I$(srcdir) -I.. -I../intl -I$(top_srcdir)/intl
DISTCLEANFILES = fnmatch.h
all-local execute.lo javacomp.lo javaexec.lo pipe-bidi.lo pipe-in.lo pipe-out.lo progname.lo wait-process.lo xerror.lo: @STDBOOL_H@
all-local c-ctype.lo execute.lo javacomp.lo javaexec.lo pipe-bidi.lo pipe-in.lo pipe-out.lo progname.lo tmpdir.lo wait-process.lo xerror.lo: @STDBOOL_H@
stdbool.h: stdbool.h.in
cp $(srcdir)/stdbool.h.in stdbool.h
MOSTLYCLEANFILES = @STDBOOL_H@

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1992,95,96,97,98,99,2000,2001 Free Software Foundation, Inc.
/* Copyright (C) 1992,1995-1999,2000-2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -60,7 +60,6 @@ __libc_lock_define_initialized (static, envlock)
/* In the GNU C library we must keep the namespace clean. */
#ifdef _LIBC
# define setenv __setenv
# define unsetenv __unsetenv
# define clearenv __clearenv
# define tfind __tfind
# define tsearch __tsearch
@ -267,43 +266,6 @@ setenv (name, value, replace)
return __add_to_environ (name, value, NULL, replace);
}
int
unsetenv (name)
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;
}
/* The `clearenv' was planned to be added to POSIX.1 but probably
never made it. Nevertheless the POSIX.9 standard (POSIX bindings
for Fortran 77) requires this function. */
@ -326,6 +288,7 @@ clearenv ()
return 0;
}
#ifdef _LIBC
static void
free_mem (void)
@ -341,9 +304,7 @@ text_set_element (__libc_subfreeres, free_mem);
# undef setenv
# undef unsetenv
# undef clearenv
weak_alias (__setenv, setenv)
weak_alias (__unsetenv, unsetenv)
weak_alias (__clearenv, clearenv)
#endif

View File

@ -23,26 +23,32 @@
# endif
#endif
#if HAVE_SETENV
#if HAVE_SETENV || HAVE_UNSETENV
/* Get setenv(), unsetenv() declarations. */
#include <stdlib.h>
#else
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if !HAVE_SETENV
/* Set NAME to VALUE in the environment.
If REPLACE is nonzero, overwrite an existing value. */
extern int setenv PARAMS ((const char *name, const char *value, int replace));
#endif
#if !HAVE_UNSETENV
/* Remove the variable NAME from the environment. */
extern int unsetenv PARAMS ((const char *name));
#endif
#ifdef __cplusplus
}
#endif
#endif

105
lib/unsetenv.c Normal file
View File

@ -0,0 +1,105 @@
/* Copyright (C) 1992,1995-1999,2000-2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#if !_LIBC
# if !defined errno && !defined HAVE_ERRNO_DECL
extern int errno;
# endif
# define __set_errno(ev) ((errno) = (ev))
#endif
#if _LIBC || HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if _LIBC || HAVE_STRING_H
# include <string.h>
#endif
#if _LIBC || HAVE_UNISTD_H
# include <unistd.h>
#endif
#if !_LIBC
# define __environ environ
# ifndef HAVE_ENVIRON_DECL
extern char **environ;
# endif
#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
/* In the GNU C library we must keep the namespace clean. */
#ifdef _LIBC
# define unsetenv __unsetenv
#endif
int
unsetenv (name)
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;
}
#ifdef _LIBC
# undef unsetenv
weak_alias (__unsetenv, unsetenv)
#endif

View File

@ -1,3 +1,7 @@
2002-03-04 Bruno Haible <bruno@clisp.org>
* setenv.m4 (gt_FUNC_SETENV): Also check whether unsetenv is missing.
2002-03-02 Bruno Haible <bruno@clisp.org>
* gettext.m4 (AM_GNU_GETTEXT): Set LIBINTL and LTLIBINTL to empty if

View File

@ -1,4 +1,4 @@
# setenv.m4 serial 1 (gettext-0.11)
# setenv.m4 serial 2 (gettext-0.11.1)
dnl Copyright (C) 2001-2002 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
@ -29,7 +29,7 @@ AC_DEFUN([gt_CHECK_VAR_DECL],
AC_DEFUN([gt_FUNC_SETENV],
[
AC_REPLACE_FUNCS(setenv)
AC_REPLACE_FUNCS(setenv unsetenv)
AC_CHECK_HEADERS(search.h stdlib.h string.h unistd.h)
AC_CHECK_FUNCS(tsearch)
gt_CHECK_VAR_DECL([#include <errno.h>], errno)