[tor-commits] [tor/master] Don't redeclare environ if std headers already did

nickm at torproject.org nickm at torproject.org
Mon Feb 20 18:03:14 UTC 2012


commit bc66878bdea0250991fc99b2d023146f67a6f4bb
Author: Sebastian Hahn <sebastian at torproject.org>
Date:   Sun Feb 19 16:09:08 2012 +0100

    Don't redeclare environ if std headers already did
    
    This would cause a redundant redeclaration warning on some versions of
    Linux otherwise.
---
 configure.in        |   16 ++++++++++++++++
 src/common/compat.c |   10 ++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/configure.in b/configure.in
index 7b6d8fb..7415ce8 100644
--- a/configure.in
+++ b/configure.in
@@ -1086,6 +1086,17 @@ int main(int c, char **v) { puts(__FUNCTION__); }])],
   tor_cv_have_FUNCTION_macro=yes,
   tor_cv_have_FUNCTION_macro=no))
 
+AC_CACHE_CHECK([whether we have extern char **environ already declared],
+  tor_cv_have_environ_declared,
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([
+/* We define _GNU_SOURCE here because it is also defined in compat.c.
+ * Without it environ doesn't get declared. */
+#define _GNU_SOURCE
+#include <unistd.h>
+int main(int c, char **v) { char **t = environ; }])],
+  tor_cv_have_environ_declared=yes,
+  tor_cv_have_environ_declared=no))
+
 if test "$tor_cv_have_func_macro" = 'yes'; then
   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
 fi
@@ -1099,6 +1110,11 @@ if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
            [Defined if the compiler supports __FUNCTION__])
 fi
 
+if test "$tor_cv_have_environ_declared" = 'yes'; then
+  AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED__, 1,
+           [Defined if we have extern char **environ already declared])
+fi
+
 # $prefix stores the value of the --prefix command line option, or
 # NONE if the option wasn't set.  In the case that it wasn't set, make
 # it be the default, so that we can use it to expand directories now.
diff --git a/src/common/compat.c b/src/common/compat.c
index f25a8ac..30bde3d 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -16,7 +16,11 @@
  * We also need it to make memmem get defined (where available)
  */
 /* XXXX023 We should just use AC_USE_SYSTEM_EXTENSIONS in our autoconf,
- * and get this (and other important stuff!) automatically */
+ * and get this (and other important stuff!) automatically. Once we do that,
+ * make sure to also change the extern char **environ detection in
+ * configure.in, because whether that is declared or not depends on whether
+ * we have _GNU_SOURCE defined! Maybe that means that once we take this out,
+ * we can also take out the configure check. */
 #define _GNU_SOURCE
 
 #include "compat.h"
@@ -1663,9 +1667,11 @@ make_path_absolute(char *fname)
 }
 
 #ifndef HAVE__NSGETENVIRON
-/* FreeBSD needs this; it doesn't seem to hurt other platforms. */
+#ifndef HAVE_EXTERN_ENVIRON_DECLARED__
+/* Some platforms declare environ under some circumstances, others don't. */
 extern char **environ;
 #endif
+#endif
 
 /** Return the current environment. This is a portable replacement for
  * 'environ'. */





More information about the tor-commits mailing list