From: Bruno Haible Date: Mon, 4 Mar 2002 20:29:02 +0000 (+0000) Subject: Portability to AIX 4.3.3. X-Git-Tag: v0.11.1~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=201ac6ddda2b93ce0888c1bc52a23010169709ae;p=thirdparty%2Fgettext.git Portability to AIX 4.3.3. --- diff --git a/lib/ChangeLog b/lib/ChangeLog index 4953d0274..371e4f2a4 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,12 @@ +2002-03-04 Bruno Haible + + 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 * strncasecmp.c (__strncasecmp): Trivial simplification. diff --git a/lib/Makefile.am b/lib/Makefile.am index 39471eca5..a566bd891 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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@ diff --git a/lib/setenv.c b/lib/setenv.c index 9653604de..c0047a149 100644 --- a/lib/setenv.c +++ b/lib/setenv.c @@ -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 diff --git a/lib/setenv.h b/lib/setenv.h index 594787785..49e7c5d31 100644 --- a/lib/setenv.h +++ b/lib/setenv.h @@ -23,26 +23,32 @@ # endif #endif -#if HAVE_SETENV +#if HAVE_SETENV || HAVE_UNSETENV /* Get setenv(), unsetenv() declarations. */ #include -#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)); -#ifdef __cplusplus -} #endif +#ifdef __cplusplus +} #endif diff --git a/lib/unsetenv.c b/lib/unsetenv.c new file mode 100644 index 000000000..56b35f06a --- /dev/null +++ b/lib/unsetenv.c @@ -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 +#endif + +#include +#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 +#endif +#if _LIBC || HAVE_STRING_H +# include +#endif +#if _LIBC || HAVE_UNISTD_H +# include +#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 +__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 diff --git a/m4/ChangeLog b/m4/ChangeLog index a7df09907..d13c147a6 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,7 @@ +2002-03-04 Bruno Haible + + * setenv.m4 (gt_FUNC_SETENV): Also check whether unsetenv is missing. + 2002-03-02 Bruno Haible * gettext.m4 (AM_GNU_GETTEXT): Set LIBINTL and LTLIBINTL to empty if diff --git a/m4/setenv.m4 b/m4/setenv.m4 index b27d05746..832193b5f 100644 --- a/m4/setenv.m4 +++ b/m4/setenv.m4 @@ -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)