From: Eric Blake Date: Thu, 31 Dec 2009 20:28:59 +0000 (-0700) Subject: unistd: warn on use of environ without module X-Git-Tag: v0.1~4762 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=718991da5f5026e1a8ce2efcca58359d9b67b2f5;p=gnulib.git unistd: warn on use of environ without module _GL_WARN_ON_USE only works for functions; so we wrap access to environ through a function when CFLAGS has -DGNULIB_POSIXCHECK=1. * modules/unistd (Depends-on): Add warn-on-use. (Makefile.am): Provide new substitutions. * m4/unistd_h.m4 (gl_UNISTD_H): Check for inline and environ. * lib/unistd.in.h (environ): Wrap with a warning helper function. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index c898b9a09..5fa0e6c44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2010-01-11 Eric Blake + unistd: warn on use of environ without module + * modules/unistd (Depends-on): Add warn-on-use. + (Makefile.am): Provide new substitutions. + * m4/unistd_h.m4 (gl_UNISTD_H): Check for inline and environ. + * lib/unistd.in.h (environ): Wrap with a warning helper function. + stdio: warn on suspicious uses * modules/stdio (Depends-on): Add warn-on-use. (Makefile.am): Provide new substitutions. diff --git a/lib/unistd.in.h b/lib/unistd.in.h index a353b0c08..018dd5f04 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -118,6 +118,8 @@ /* The definition of _GL_ARG_NONNULL is copied here. */ +/* The definition of _GL_WARN_ON_USE is copied here. */ + /* OS/2 EMX lacks these macros. */ #ifndef STDIN_FILENO @@ -250,11 +252,17 @@ 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) +# if HAVE_RAW_DECL_ENVIRON +static inline char *** +rpl_environ (void) +{ + return &environ; +} +_GL_WARN_ON_USE (rpl_environ, "environ is unportable - " + "use gnulib module environ for portability"); +# undef environ +# define environ (*rpl_environ ()) +# endif #endif diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index f3074ea8a..aacec2b15 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 37 +# unistd_h.m4 serial 38 dnl Copyright (C) 2006-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -11,6 +11,7 @@ AC_DEFUN([gl_UNISTD_H], dnl Use AC_REQUIRE here, so that the default behavior below is expanded dnl once only, before all statements that occur in other macros. AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + AC_REQUIRE([AC_C_INLINE]) gl_CHECK_NEXT_HEADERS([unistd.h]) @@ -21,6 +22,15 @@ AC_DEFUN([gl_UNISTD_H], HAVE_UNISTD_H=0 fi AC_SUBST([HAVE_UNISTD_H]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[#include +/* Some systems declare environ in the wrong header. */ +#ifndef __GLIBC__ +# include +#endif + ]], [environ]) ]) AC_DEFUN([gl_UNISTD_MODULE_INDICATOR], diff --git a/modules/unistd b/modules/unistd index f55783745..055b989b8 100644 --- a/modules/unistd +++ b/modules/unistd @@ -6,10 +6,11 @@ m4/unistd_h.m4 lib/unistd.in.h Depends-on: +arg-nonnull include_next link-warning -arg-nonnull stddef +warn-on-use configure.ac: gl_UNISTD_H @@ -19,7 +20,7 @@ BUILT_SOURCES += unistd.h # We need the following in order to create an empty placeholder for # when the system doesn't have one. -unistd.h: unistd.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) +unistd.h: unistd.in.h $(LINK_WARNING_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \ @@ -121,6 +122,7 @@ unistd.h: unistd.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/unistd.in.h; \ } > $@-t && \ mv $@-t $@