Test for ctime_r prototype.
authorScott Cantor <cantor.2@osu.edu>
Thu, 15 Nov 2007 23:01:18 +0000 (23:01 +0000)
committerScott Cantor <cantor.2@osu.edu>
Thu, 15 Nov 2007 23:01:18 +0000 (23:01 +0000)
configure.ac
shibsp/util/TemplateParameters.cpp

index 1c72dff..65fa7a6 100644 (file)
@@ -69,7 +69,7 @@ AC_STRUCT_TM
 # Checks for library functions.
 AC_FUNC_STRFTIME
 AC_FUNC_STRERROR_R
-AC_CHECK_FUNCS([strchr strdup strstr timegm gmtime_r ctime_r strtok_r strcasecmp])
+AC_CHECK_FUNCS([strchr strdup strstr timegm gmtime_r strtok_r strcasecmp])
 
 # checks for pthreads
 ACX_PTHREAD([enable_threads="pthread"],[enable_threads="no"])
@@ -82,6 +82,36 @@ else
     CXXFLAGS="$PTHREAD_CFLAGS $CXXFLAGS"
 fi
 
+# Thank you Solaris, really.
+AC_MSG_CHECKING(for ctime_r)
+ if test -z "$ac_cv_ctime_args"; then
+     AC_TRY_COMPILE(
+     [#include <time.h>],
+     [
+         time_t clock;
+         char buf[26];
+         ctime_r(&clock, buf);
+     ], ac_cv_ctime_args=2)
+
+     AC_TRY_COMPILE(
+     [#include <time.h>],
+     [
+         time_t clock;
+         char buf[26];
+         ctime_r(&clock, buf, 26);
+     ], ac_cv_ctime_args=3)
+ fi
+ if test -z "$ac_cv_ctime_args"; then
+     AC_MSG_RESULT(no)
+ else
+     if test "$ac_cv_ctime_args" = 2; then
+         AC_DEFINE(HAVE_CTIME_R_2)
+     elif test "$ac_cv_ctime_args" = 3; then
+         AC_DEFINE(HAVE_CTIME_R_3)
+     fi
+     AC_MSG_RESULT([yes, and it takes $ac_cv_ctime_args arguments])
+ fi 
+
 # OpenSSL settings
 AC_ARG_WITH(openssl,
     AC_HELP_STRING([--with-openssl=PATH], [where openssl is installed]),
index 93a5a42..f83abd2 100644 (file)
@@ -37,7 +37,10 @@ void TemplateParameters::setPropertySet(const PropertySet* props)
 
     // Create a timestamp.
     time_t now = time(NULL);
-#ifdef HAVE_CTIME_R
+#if defined(HAVE_CTIME_R_2)
+    char timebuf[32];
+    m_map["now"] = ctime_r(&now,timebuf);
+#elif defined(HAVE_CTIME_R_3)
     char timebuf[32];
     m_map["now"] = ctime_r(&now,timebuf,sizeof(timebuf));
 #else