From 22eb7728a25fbfb7ba1a591db0f70fe5a0e266e0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 24 Feb 2008 16:40:15 +0100 Subject: [PATCH] New module 'environ'. --- ChangeLog | 27 +++++++++++++++++++++++++++ doc/posix-functions/environ.texi | 15 ++++++++------- lib/execute.c | 6 +----- lib/pipe.c | 6 +----- lib/setenv.c | 5 +---- lib/unistd.in.h | 22 +++++++++++++++++++++- lib/unsetenv.c | 5 +---- m4/environ.m4 | 36 ++++++++++++++++++++++++++++++++++++ m4/setenv.m4 | 27 ++++----------------------- m4/unistd_h.m4 | 6 ++++-- modules/environ | 24 ++++++++++++++++++++++++ modules/execute | 1 + modules/pipe | 1 + modules/setenv | 1 + modules/unistd | 2 ++ modules/unsetenv | 1 + 16 files changed, 134 insertions(+), 51 deletions(-) create mode 100644 m4/environ.m4 create mode 100644 modules/environ diff --git a/ChangeLog b/ChangeLog index 926aea507..36e7e06e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,32 @@ 2008-02-24 Bruno Haible + New module 'environ'. + * modules/environ: New file. + * lib/unistd.in.h (environ): New declaration. + * m4/environ.m4: New file. + (gt_CHECK_VAR_DECL): Moved here from m4/setenv.m4. Undefine gt_cv_var + after use. + * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_ENVIRON and + HAVE_DECL_ENVIRON. + * modules/unistd (Makefile.am): Substitute also GNULIB_ENVIRON and + HAVE_DECL_ENVIRON. + * doc/posix-functions/environ.texi: Mention module 'environ'. Remove + wrong claim that 'environ' is missing on some systems. + * modules/execute (Depends-on): Add environ. + * lib/execute.c (environ): Remove fallback declaration. + * modules/pipe (Depends-on): Add environ. + * lib/pipe.c (environ): Remove fallback declaration. + * modules/setenv (Depends-on): Add environ. + * lib/setenv.c (environ): Remove fallback declaration. + * modules/unsetenv (Depends-on): Add environ. + * lib/unsetenv.c (environ): Remove fallback declaration. + * m4/setenv.m4 (gt_CHECK_VAR_DECL): Remove macro. Moved to + m4/environ.m4. + (gl_PREREQ_SETENV): Require gl_ENVIRON instead of testing for environ. + (gl_PREREQ_UNSETENV): Likewise. + +2008-02-24 Bruno Haible + * doc/posix-functions/environ.texi: Document the MacOS X problem. 2008-02-20 Bob Proulx diff --git a/doc/posix-functions/environ.texi b/doc/posix-functions/environ.texi index ba027d90a..e4100fb87 100644 --- a/doc/posix-functions/environ.texi +++ b/doc/posix-functions/environ.texi @@ -4,17 +4,14 @@ POSIX specification: @url{http://www.opengroup.org/susv3xsh/environ.html} -Gnulib module: --- +Gnulib module: environ Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item -This variable is missing on some platforms: -MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, IRIX 6.5, OSF/1 5.1, Cygwin. +POSIX does not require this variable to be declared, and it is indeed not +declared on some platforms: +MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, IRIX 6.5, Solaris 10. @item On MacOS X 10, this variable is not declared. Up to MacOS X 10.4, one can use @smallexample @@ -27,6 +24,10 @@ shared libraries on MacOS X 10.5. Here is a workaround: Instead, one can use #define environ (*_NSGetEnviron()) @end smallexample This works at least on MacOS X 10.3 and newer. +@end itemize + +Portability problems not fixed by Gnulib: +@itemize @item The address of this variable is not a compile-time constant on some platforms: mingw. diff --git a/lib/execute.c b/lib/execute.c index 30ce0009a..cfac1962d 100644 --- a/lib/execute.c +++ b/lib/execute.c @@ -1,5 +1,5 @@ /* Creation of autonomous subprocesses. - Copyright (C) 2001-2004, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2008 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -54,10 +54,6 @@ #endif -#if ! HAVE_ENVIRON_DECL -extern char **environ; -#endif - #ifndef STDIN_FILENO # define STDIN_FILENO 0 #endif diff --git a/lib/pipe.c b/lib/pipe.c index f10cc95fe..e62d137e0 100644 --- a/lib/pipe.c +++ b/lib/pipe.c @@ -1,5 +1,5 @@ /* Creation of subprocesses, communicating via pipes. - Copyright (C) 2001-2004, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2008 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -53,10 +53,6 @@ #endif -#if ! HAVE_ENVIRON_DECL -extern char **environ; -#endif - #ifndef STDIN_FILENO # define STDIN_FILENO 0 #endif diff --git a/lib/setenv.c b/lib/setenv.c index ea1d1167f..83b52b88b 100644 --- a/lib/setenv.c +++ b/lib/setenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992,1995-1999,2000-2003,2005-2007 Free Software Foundation, Inc. +/* Copyright (C) 1992,1995-1999,2000-2003,2005-2008 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 @@ -40,9 +40,6 @@ #if !_LIBC # define __environ environ -# ifndef HAVE_ENVIRON_DECL -extern char **environ; -# endif #endif #if _LIBC diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 5400c8636..346b8b4be 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -1,5 +1,5 @@ /* Substitute for and wrapper around . - Copyright (C) 2004-2007 Free Software Foundation, Inc. + Copyright (C) 2004-2008 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 @@ -86,6 +86,26 @@ extern int dup2 (int oldfd, int newfd); #endif +#if @GNULIB_ENVIRON@ +# if !@HAVE_DECL_ENVIRON@ +/* Set of environment variables and values. An array of strings of the form + "VARIABLE=VALUE", terminated with a NULL. */ +# if defined __APPLE__ && defined __MACH__ +# include +# define environ (*_NSGetEnviron ()) +# else +extern char **environ; +# endif +# endif +#elif defined GNULIB_POSIXCHECK +# undef environ +# define environ \ + (GL_LINK_WARNING ("environ is unportable - " \ + "use gnulib module environ for portability"), \ + environ) +#endif + + #if @GNULIB_FCHDIR@ # if @REPLACE_FCHDIR@ diff --git a/lib/unsetenv.c b/lib/unsetenv.c index c783997a2..73ea878a6 100644 --- a/lib/unsetenv.c +++ b/lib/unsetenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992,1995-1999,2000-2002,2005-2007 Free Software Foundation, Inc. +/* Copyright (C) 1992,1995-1999,2000-2002,2005-2008 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 @@ -29,9 +29,6 @@ #if !_LIBC # define __environ environ -# ifndef HAVE_ENVIRON_DECL -extern char **environ; -# endif #endif #if _LIBC diff --git a/m4/environ.m4 b/m4/environ.m4 new file mode 100644 index 000000000..fac0c0555 --- /dev/null +++ b/m4/environ.m4 @@ -0,0 +1,36 @@ +# environ.m4 serial 1 +dnl Copyright (C) 2001-2004, 2006-2008 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_ENVIRON], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + dnl Persuade glibc to declare environ. + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + gt_CHECK_VAR_DECL([#include ], environ) + if test $gt_cv_var_environ_declaration != yes; then + HAVE_DECL_ENVIRON=0 + fi +]) + +# Check if a variable is properly declared. +# gt_CHECK_VAR_DECL(includes,variable) +AC_DEFUN([gt_CHECK_VAR_DECL], +[ + define([gt_cv_var], [gt_cv_var_]$2[_declaration]) + AC_MSG_CHECKING([if $2 is properly declared]) + AC_CACHE_VAL(gt_cv_var, [ + AC_TRY_COMPILE([$1 + extern struct { int foo; } $2;], + [$2.foo = 1;], + gt_cv_var=no, + gt_cv_var=yes)]) + AC_MSG_RESULT($gt_cv_var) + if test $gt_cv_var = yes; then + AC_DEFINE([HAVE_]translit($2, [a-z], [A-Z])[_DECL], 1, + [Define if you have the declaration of $2.]) + fi + undefine([gt_cv_var]) +]) diff --git a/m4/setenv.m4 b/m4/setenv.m4 index bbb5548ff..7af13d724 100644 --- a/m4/setenv.m4 +++ b/m4/setenv.m4 @@ -1,5 +1,5 @@ -# setenv.m4 serial 9 -dnl Copyright (C) 2001-2004, 2006-2007 Free Software Foundation, Inc. +# setenv.m4 serial 10 +dnl Copyright (C) 2001-2004, 2006-2008 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -53,38 +53,19 @@ int unsetenv(); fi ]) -# Check if a variable is properly declared. -# gt_CHECK_VAR_DECL(includes,variable) -AC_DEFUN([gt_CHECK_VAR_DECL], -[ - define([gt_cv_var], [gt_cv_var_]$2[_declaration]) - AC_MSG_CHECKING([if $2 is properly declared]) - AC_CACHE_VAL(gt_cv_var, [ - AC_TRY_COMPILE([$1 - extern struct { int foo; } $2;], - [$2.foo = 1;], - gt_cv_var=no, - gt_cv_var=yes)]) - AC_MSG_RESULT($gt_cv_var) - if test $gt_cv_var = yes; then - AC_DEFINE([HAVE_]translit($2, [a-z], [A-Z])[_DECL], 1, - [Define if you have the declaration of $2.]) - fi -]) - # Prerequisites of lib/setenv.c. AC_DEFUN([gl_PREREQ_SETENV], [ AC_REQUIRE([AC_FUNC_ALLOCA]) + AC_REQUIRE([gl_ENVIRON]) AC_CHECK_HEADERS_ONCE(unistd.h) AC_CHECK_HEADERS(search.h) AC_CHECK_FUNCS(tsearch) - gt_CHECK_VAR_DECL([#include ], environ) ]) # Prerequisites of lib/unsetenv.c. AC_DEFUN([gl_PREREQ_UNSETENV], [ + AC_REQUIRE([gl_ENVIRON]) AC_CHECK_HEADERS_ONCE(unistd.h) - gt_CHECK_VAR_DECL([#include ], environ) ]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index 4b8857ca5..e8ccab16e 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,5 +1,5 @@ -# unistd_h.m4 serial 10 -dnl Copyright (C) 2006-2007 Free Software Foundation, Inc. +# unistd_h.m4 serial 11 +dnl Copyright (C) 2006-2008 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -34,6 +34,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], [ GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN]) GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2]) + GNULIB_ENVIRON=0; AC_SUBST([GNULIB_ENVIRON]) GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR]) GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE]) GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD]) @@ -49,6 +50,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE]) HAVE_READLINK=1; AC_SUBST([HAVE_READLINK]) HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP]) + HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON]) HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R]) HAVE_OS_H=0; AC_SUBST([HAVE_OS_H]) HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H]) diff --git a/modules/environ b/modules/environ new file mode 100644 index 000000000..30576194c --- /dev/null +++ b/modules/environ @@ -0,0 +1,24 @@ +Description: +environ variable: storage of environment variables. + +Files: +m4/environ.m4 + +Depends-on: +unistd + +configure.ac: +gl_ENVIRON +gl_UNISTD_MODULE_INDICATOR([environ]) + +Makefile.am: + +Include: +#include + +License: +LGPLv2+ + +Maintainer: +Bruno Haible + diff --git a/modules/execute b/modules/execute index 00f186101..d5f6ce6cf 100644 --- a/modules/execute +++ b/modules/execute @@ -16,6 +16,7 @@ gettext-h stdbool strpbrk unistd +environ configure.ac: gl_EXECUTE diff --git a/modules/pipe b/modules/pipe index 0aab325f1..aef9389aa 100644 --- a/modules/pipe +++ b/modules/pipe @@ -16,6 +16,7 @@ gettext-h stdbool strpbrk unistd +environ configure.ac: gl_PIPE diff --git a/modules/setenv b/modules/setenv index 1c93bfb5c..0458c388d 100644 --- a/modules/setenv +++ b/modules/setenv @@ -10,6 +10,7 @@ stdlib malloca alloca-opt unistd +environ configure.ac: gl_FUNC_SETENV diff --git a/modules/unistd b/modules/unistd index 4d16cf3ab..88fc993c8 100644 --- a/modules/unistd +++ b/modules/unistd @@ -25,6 +25,7 @@ unistd.h: unistd.in.h -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \ -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \ -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \ + -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \ -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \ -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \ -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \ @@ -39,6 +40,7 @@ unistd.h: unistd.in.h -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \ -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \ + -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \ -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \ -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \ -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \ diff --git a/modules/unsetenv b/modules/unsetenv index 261c8e4d6..6dff883c7 100644 --- a/modules/unsetenv +++ b/modules/unsetenv @@ -8,6 +8,7 @@ m4/setenv.m4 Depends-on: stdlib unistd +environ configure.ac: gl_FUNC_UNSETENV -- 2.11.0