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

collectd at wattapower.net collectd at wattapower.net
Fri Apr 30 15:31:59 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.

Instead of trying to compile a test program, this patch tests whether
the function is declared in <string.h> when _REENTRANT is not defined and when it is.
It then changes CFLAGS accordingly.

The actual existence of the function is tested also, so we are sure we
have both the code and its declaration.
---
 configure.in |   76 +++++++++++++---------------------------------------------
 1 files changed, 17 insertions(+), 59 deletions(-)

diff --git a/configure.in b/configure.in
index 6b66b2a..7407dd1 100644
--- a/configure.in
+++ b/configure.in
@@ -459,67 +459,25 @@ AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr
 
 AC_FUNC_STRERROR_R
 
-AC_CACHE_CHECK([for strtok_r],
-  [c_cv_have_strtok_r_default],
-  AC_LINK_IFELSE(
-    AC_LANG_PROGRAM(
-    [[[[
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-    ]]]],
-    [[[[
-      char buffer[] = "foo,bar,baz";
-      char *token;
-      char *dummy;
-      char *saveptr;
-
-      dummy = buffer;
-      saveptr = NULL;
-      while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
-      {
-	dummy = NULL;
-        printf ("token = %s;\n", token);
-      }
-    ]]]]),
-    [c_cv_have_strtok_r_default="yes"],
-    [c_cv_have_strtok_r_default="no"]
-  )
-)
-
-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(
-      [[[[
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-      ]]]],
-      [[[[
-        char buffer[] = "foo,bar,baz";
-        char *token;
-        char *dummy;
-        char *saveptr;
-
-        dummy = buffer;
-        saveptr = NULL;
-        while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
-        {
-	  dummy = NULL;
-          printf ("token = %s;\n", token);
-        }
-      ]]]]),
-      [c_cv_have_strtok_r_reentrant="yes"],
-      [AC_MSG_FAILURE([strtok_r isn't available. Please file a bugreport!])]
-    )
-  )
-fi
+AC_CHECK_DECL(strtok_r, [], [],
+              [
+                #include <string.h>
+              ])
+if test "x$ac_cv_have_decl_strtok_r" = "xno"
+then
+	AC_MSG_NOTICE([Retrying with -D_REENTRANT])
+	# reset cached result to force re-check
+	unset ac_cv_have_decl_strtok_r
+	AC_CHECK_DECL(strtok_r,
+	              [ CFLAGS=$CFLAGS" -D_REENTRANT=1" ],
+		      [],
+	              [
+	               #define _REENTRANT 1
+	               #include <string.h>
+	              ])
+fi
+
+AC_CHECK_FUNC(strtok_r, [], [AC_MSG_FAILURE([strtok_r isn't available. Please file a bugreport!])])
 
 AC_CHECK_FUNCS(getpwnam_r getgrnam_r setgroups regcomp regerror regexec regfree)
 
-- 
1.7.0.4




More information about the collectd mailing list