[collectd] [PATCH] Fix strtok_r check in configure.in

collectd at wattapower.net collectd at wattapower.net
Fri Apr 30 11:16:17 CEST 2010


From: Aurélien Reynaud <collectd at wattapower.net>

The need for -D_REENTRANT was not correctly detected, because the
warnings about undeclared functions do not cause the test
program compilation to fail by default.

The patch mainly adds -Werror to the CFLAGS during compilation of the
test program to force the check to fail on warnings.

It assumes -Werror is understood by the compiler, but the libperl
checks do the same, so it shouldn't introduce new problems...

Signed-off-by: Aurélien Reynaud <collectd at wattapower.net>
---
 configure.in |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/configure.in b/configure.in
index 6b66b2a..8abed22 100644
--- a/configure.in
+++ b/configure.in
@@ -459,6 +459,8 @@ AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr
 
 AC_FUNC_STRERROR_R
 
+SAVEDCFLAGS=$CFLAGS
+CFLAGS=$CFLAGS" -Werror"
 AC_CACHE_CHECK([for strtok_r],
   [c_cv_have_strtok_r_default],
   AC_LINK_IFELSE(
@@ -478,7 +480,7 @@ AC_CACHE_CHECK([for strtok_r],
       saveptr = NULL;
       while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
       {
-	dummy = NULL;
+        dummy = NULL;
         printf ("token = %s;\n", token);
       }
     ]]]]),
@@ -489,14 +491,12 @@ AC_CACHE_CHECK([for strtok_r],
 
 if test "x$c_cv_have_strtok_r_default" = "xno"
 then
-  SAVE_CFLAGS="$CFLAGS"
-  CFLAGS="$CFLAGS -D_REENTRANT=1"
-
   AC_CACHE_CHECK([if strtok_r needs _REENTRANT],
     [c_cv_have_strtok_r_reentrant],
     AC_LINK_IFELSE(
       AC_LANG_PROGRAM(
       [[[[
+#define _REENTRANT 1
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -511,7 +511,7 @@ then
         saveptr = NULL;
         while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
         {
-	  dummy = NULL;
+          dummy = NULL;
           printf ("token = %s;\n", token);
         }
       ]]]]),
@@ -520,6 +520,11 @@ then
     )
   )
 fi
+CFLAGS=$SAVEDCFLAGS
+if test "x$c_cv_have_strtok_r_reentrant" = "xyes"
+then
+        CFLAGS=$CFLAGS" -D_REENTRANT=1"
+fi
 
 AC_CHECK_FUNCS(getpwnam_r getgrnam_r setgroups regcomp regerror regexec regfree)
 
-- 
1.7.0.4




More information about the collectd mailing list