From 81e61b220d430779361b384b360b58a711cfd046 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 26 Dec 2007 16:20:10 +0100 Subject: [PATCH] Split setenv module into setenv and unsetenv. Get rid of setenv.h. --- NEWS | 5 ++++ doc/functions/unsetenv.texi | 7 +++--- lib/getdate.y | 1 - lib/relocwrapper.c | 1 - lib/setenv.c | 4 ++- lib/setenv.h | 53 ---------------------------------------- lib/stdlib.in.h | 25 ++++++++++++++++++- lib/unsetenv.c | 6 +++-- lib/xsetenv.c | 1 - lib/xsetenv.h | 2 +- m4/setenv.m4 | 12 +++++++-- m4/stdlib_h.m4 | 7 +++++- modules/getdate | 1 + modules/relocatable-prog-wrapper | 2 +- modules/setenv | 8 +++--- modules/stdlib | 5 ++++ modules/unsetenv | 26 ++++++++++++++++++++ modules/xsetenv | 1 + 18 files changed, 94 insertions(+), 73 deletions(-) delete mode 100644 lib/setenv.h create mode 100644 modules/unsetenv diff --git a/NEWS b/NEWS index adb016372..c30b27207 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,11 @@ User visible incompatible changes Date Modules Changes +2007-12-24 setenv The include file is changed from "setenv.h" to + . Also, the unsetenv function is no + longer declared in this module; use the 'unsetenv' + module if you need it. + 2007-12-03 getpagesize The include file is changed from "getpagesize.h" to . diff --git a/doc/functions/unsetenv.texi b/doc/functions/unsetenv.texi index 82b00d4a6..644182a37 100644 --- a/doc/functions/unsetenv.texi +++ b/doc/functions/unsetenv.texi @@ -11,11 +11,12 @@ Portability problems fixed by Gnulib: @item This function is missing on some platforms: AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, mingw, BeOS. +@item +This function has the return type @samp{void} instead of @samp{int} on some +platforms: +MacOS X 10.3, FreeBSD 6.0, NetBSD 1.6, OpenBSD 3.8, OSF/1 5.1. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function has the return type @samp{void} instead of @samp{int} on some -platforms. @end itemize diff --git a/lib/getdate.y b/lib/getdate.y index e292f5e46..1ed914f31 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -66,7 +66,6 @@ #include #include -#include "setenv.h" #include "xalloc.h" diff --git a/lib/relocwrapper.c b/lib/relocwrapper.c index ca186c357..76e355916 100644 --- a/lib/relocwrapper.c +++ b/lib/relocwrapper.c @@ -53,7 +53,6 @@ #include "progname.h" #include "relocatable.h" -#include "setenv.h" #include "c-ctype.h" /* Return a copy of the filename, with an extra ".bin" at the end. diff --git a/lib/setenv.c b/lib/setenv.c index 75488be0b..ea1d1167f 100644 --- a/lib/setenv.c +++ b/lib/setenv.c @@ -19,12 +19,14 @@ #endif #include +/* Specification. */ +#include + #include #ifndef __set_errno # define __set_errno(ev) ((errno) = (ev)) #endif -#include #include #if _LIBC || HAVE_UNISTD_H # include diff --git a/lib/setenv.h b/lib/setenv.h deleted file mode 100644 index 9f5d0b7ec..000000000 --- a/lib/setenv.h +++ /dev/null @@ -1,53 +0,0 @@ -/* Setting environment variables. - Copyright (C) 2001-2004, 2007 Free Software Foundation, Inc. - - 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 3 of the License, 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, see . */ - -#if HAVE_SETENV || HAVE_UNSETENV - -/* Get setenv(), unsetenv() declarations. */ -# include - -#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 (const char *name, const char *value, int replace); - -#endif - -#if HAVE_UNSETENV - -# if VOID_UNSETENV -/* On some systems, unsetenv() returns void. - This is the case for FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */ -# define unsetenv(name) ((unsetenv)(name), 0) -# endif - -#else - -/* Remove the variable NAME from the environment. */ -extern int unsetenv (const char *name); - -#endif - -#ifdef __cplusplus -} -#endif diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index dc9f98f8d..100ff5265 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright (C) 1995, 2001-2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1995, 2001-2004, 2006-2007 Free Software Foundation, Inc. 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 @@ -176,6 +176,29 @@ extern int putenv (char *string); #endif +#if @GNULIB_SETENV@ +# if !@HAVE_SETENV@ +/* Set NAME to VALUE in the environment. + If REPLACE is nonzero, overwrite an existing value. */ +extern int setenv (const char *name, const char *value, int replace); +# endif +#endif + + +#if @GNULIB_UNSETENV@ +# if @HAVE_UNSETENV@ +# if @VOID_UNSETENV@ +/* On some systems, unsetenv() returns void. + This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */ +# define unsetenv(name) ((unsetenv)(name), 0) +# endif +# else +/* Remove the variable NAME from the environment. */ +extern int unsetenv (const char *name); +# endif +#endif + + #ifdef __cplusplus } #endif diff --git a/lib/unsetenv.c b/lib/unsetenv.c index 90b844912..c783997a2 100644 --- a/lib/unsetenv.c +++ b/lib/unsetenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992,1995-1999,2000-2002,2005-2006 Free Software Foundation, Inc. +/* Copyright (C) 1992,1995-1999,2000-2002,2005-2007 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software: you can redistribute it and/or modify @@ -16,12 +16,14 @@ #include +/* Specification. */ +#include + #include #if !_LIBC # define __set_errno(ev) ((errno) = (ev)) #endif -#include #include #include diff --git a/lib/xsetenv.c b/lib/xsetenv.c index 4939fe1b8..44e5c3f9f 100644 --- a/lib/xsetenv.c +++ b/lib/xsetenv.c @@ -21,7 +21,6 @@ #include -#include "setenv.h" #include "error.h" #include "gettext.h" diff --git a/lib/xsetenv.h b/lib/xsetenv.h index 24b59c2e9..0b65f4ffb 100644 --- a/lib/xsetenv.h +++ b/lib/xsetenv.h @@ -15,7 +15,7 @@ along with this program. If not, see . */ /* Get unsetenv(). It can be used without error checking. */ -#include "setenv.h" +#include #ifdef __cplusplus extern "C" { diff --git a/m4/setenv.m4 b/m4/setenv.m4 index d6901de24..bbb5548ff 100644 --- a/m4/setenv.m4 +++ b/m4/setenv.m4 @@ -1,4 +1,4 @@ -# setenv.m4 serial 8 +# setenv.m4 serial 9 dnl Copyright (C) 2001-2004, 2006-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -6,8 +6,10 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_SETENV], [ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) AC_CHECK_FUNCS_ONCE([setenv]) if test $ac_cv_func_setenv = no; then + HAVE_SETENV=0 AC_LIBOBJ([setenv]) gl_PREREQ_SETENV fi @@ -16,14 +18,20 @@ AC_DEFUN([gl_FUNC_SETENV], # Like gl_FUNC_SETENV, except prepare for separate compilation (no AC_LIBOBJ). AC_DEFUN([gl_FUNC_SETENV_SEPARATE], [ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) AC_CHECK_FUNCS_ONCE([setenv]) + if test $ac_cv_func_setenv = no; then + HAVE_SETENV=0 + fi gl_PREREQ_SETENV ]) AC_DEFUN([gl_FUNC_UNSETENV], [ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) AC_CHECK_FUNCS([unsetenv]) if test $ac_cv_func_unsetenv = no; then + HAVE_UNSETENV=0 AC_LIBOBJ([unsetenv]) gl_PREREQ_UNSETENV else @@ -40,7 +48,7 @@ int unsetenv(); #endif ], , gt_cv_func_unsetenv_ret='int', gt_cv_func_unsetenv_ret='void')]) if test $gt_cv_func_unsetenv_ret = 'void'; then - AC_DEFINE(VOID_UNSETENV, 1, [Define if unsetenv() returns void, not int.]) + VOID_UNSETENV=1 fi fi ]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index 278df744c..fe4ce122e 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -1,4 +1,4 @@ -# stdlib_h.m4 serial 4 +# stdlib_h.m4 serial 5 dnl Copyright (C) 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -26,12 +26,17 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP]) GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP]) GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV]) + GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV]) + GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_CALLOC_POSIX=1; AC_SUBST([HAVE_CALLOC_POSIX]) HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT]) HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX]) HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP]) HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX]) + HAVE_SETENV=1; AC_SUBST([HAVE_SETENV]) + HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV]) REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV]) + VOID_UNSETENV=0; AC_SUBST([VOID_UNSETENV]) ]) diff --git a/modules/getdate b/modules/getdate index 88b51af37..59c1abf83 100644 --- a/modules/getdate +++ b/modules/getdate @@ -15,6 +15,7 @@ gettime intprops mktime setenv +unsetenv time verify xalloc diff --git a/modules/relocatable-prog-wrapper b/modules/relocatable-prog-wrapper index 0002774d9..4a2faf5b4 100644 --- a/modules/relocatable-prog-wrapper +++ b/modules/relocatable-prog-wrapper @@ -19,7 +19,6 @@ lib/malloca.h lib/malloca.c lib/relocatable.h lib/relocatable.c -lib/setenv.h lib/setenv.c lib/strerror.c lib/c-ctype.h @@ -38,6 +37,7 @@ alloca-opt pathmax ssize_t stdbool +stdlib unistd configure.ac: diff --git a/modules/setenv b/modules/setenv index 9aaf72664..1c93bfb5c 100644 --- a/modules/setenv +++ b/modules/setenv @@ -1,26 +1,24 @@ Description: setenv() function: set an environment variable. -unsetenv() function: remove an environment variable. Files: -lib/setenv.h lib/setenv.c -lib/unsetenv.c m4/setenv.m4 Depends-on: +stdlib malloca alloca-opt unistd configure.ac: gl_FUNC_SETENV -gl_FUNC_UNSETENV +gl_STDLIB_MODULE_INDICATOR([setenv]) Makefile.am: Include: -"setenv.h" + License: LGPL diff --git a/modules/stdlib b/modules/stdlib index 1c6b4f23b..07adcd1c2 100644 --- a/modules/stdlib +++ b/modules/stdlib @@ -30,13 +30,18 @@ stdlib.h: stdlib.in.h -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \ -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \ -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \ + -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \ + -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \ -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \ -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \ -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \ + -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \ + -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \ -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ + -e 's|@''VOID_UNSETENV''@|$(VOID_UNSETENV)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/stdlib.in.h; \ } > $@-t diff --git a/modules/unsetenv b/modules/unsetenv new file mode 100644 index 000000000..261c8e4d6 --- /dev/null +++ b/modules/unsetenv @@ -0,0 +1,26 @@ +Description: +unsetenv() function: remove an environment variable. + +Files: +lib/unsetenv.c +m4/setenv.m4 + +Depends-on: +stdlib +unistd + +configure.ac: +gl_FUNC_UNSETENV +gl_STDLIB_MODULE_INDICATOR([unsetenv]) + +Makefile.am: + +Include: + + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/xsetenv b/modules/xsetenv index ea313e7fe..29319f122 100644 --- a/modules/xsetenv +++ b/modules/xsetenv @@ -8,6 +8,7 @@ lib/xsetenv.c Depends-on: setenv +unsetenv error exit gettext-h -- 2.11.0