time_r: Fix C++ test error on mingw.
authorBruno Haible <bruno@clisp.org>
Sat, 3 Apr 2010 16:52:49 +0000 (18:52 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 3 Apr 2010 16:52:49 +0000 (18:52 +0200)
ChangeLog
lib/time.in.h
m4/time_h.m4
m4/time_r.m4
modules/time

index 2c21234ff79d73d646237afb28926fda6d862032..2a88359b3c786c069df429fe25883deb2c635811 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-04-03  Bruno Haible  <bruno@clisp.org>
+
+       time_r: Fix C++ test error on mingw.
+       * lib/time.in.h (localtime_r, gmtime_r): Use modern idiom.
+       * m4/time_r.m4 (gl_TIME_R): When localtime_r does not exist, set
+       HAVE_LOCALTIME_R to 0, not REPLACE_LOCALTIME_R to 1.
+       * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize HAVE_LOCALTIME_R.
+       * modules/time (Makefile.am): Substitute HAVE_LOCALTIME_R.
+
 2010-04-03  Bruno Haible  <bruno@clisp.org>
 
        time_r: Minor updates.
index 2fdc7e75f856b4170b94eeefc6236aff6fa22d4d..35610160cbc89f20faca81b37c124d2818593760 100644 (file)
@@ -122,6 +122,11 @@ _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
 _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
                                              struct tm *restrict __result));
 #  else
+#   if ! @HAVE_LOCALTIME_R@
+_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
+                                             struct tm *restrict __result)
+                                            _GL_ARG_NONNULL ((1, 2)));
+#   endif
 _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
                                              struct tm *restrict __result));
 #  endif
@@ -137,6 +142,11 @@ _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
 _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
                                           struct tm *restrict __result));
 #  else
+#   if ! @HAVE_LOCALTIME_R@
+_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
+                                          struct tm *restrict __result)
+                                         _GL_ARG_NONNULL ((1, 2)));
+#   endif
 _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
                                           struct tm *restrict __result));
 #  endif
index f9dfe754ebbea2fa2a25d78b619bae1b3f2cb2a9..ecab80790da7e724c7ed006df43206ff53d4e42d 100644 (file)
@@ -77,6 +77,8 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
   GNULIB_STRPTIME=0;                     AC_SUBST([GNULIB_STRPTIME])
   GNULIB_TIMEGM=0;                       AC_SUBST([GNULIB_TIMEGM])
   GNULIB_TIME_R=0;                       AC_SUBST([GNULIB_TIME_R])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_LOCALTIME_R=0;                    AC_SUBST([HAVE_LOCALTIME_R])
   dnl If another module says to replace or to not replace, do that.
   dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
   dnl this lets maintainers check for portability.
index 8548cb6391e3a83823bfb27867ffb70040c84375..9e82d39ffbdfe2c86d33a8d66f3c41aae9c7c46d 100644 (file)
@@ -9,29 +9,40 @@ dnl Written by Paul Eggert.
 
 AC_DEFUN([gl_TIME_R],
 [
- dnl Persuade glibc and Solaris <time.h> to declare localtime_r.
 dnl Persuade glibc and Solaris <time.h> to declare localtime_r.
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
 
   AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
   AC_REQUIRE([AC_C_RESTRICT])
 
-  AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
-    [gl_cv_time_r_posix],
-    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-         [[#include <time.h>]],
-         [[/* We don't need to append 'restrict's to the argument types,
-              even though the POSIX signature has the 'restrict's,
-              since C99 says they can't affect type compatibility.  */
-           struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r;
-           if (ptr) return 0;
-           /* Check the return type is a pointer.  On HP-UX 10 it is 'int'.  */
-           *localtime_r (0, 0);]])],
-       [gl_cv_time_r_posix=yes],
-       [gl_cv_time_r_posix=no])])
-  if test $gl_cv_time_r_posix = yes; then
-    REPLACE_LOCALTIME_R=0
+  AC_CHECK_FUNCS_ONCE([localtime_r])
+  if test $ac_cv_func_localtime_r = yes; then
+    AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
+      [gl_cv_time_r_posix],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <time.h>]],
+            [[/* We don't need to append 'restrict's to the argument types,
+                 even though the POSIX signature has the 'restrict's,
+                 since C99 says they can't affect type compatibility.  */
+              struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r;
+              if (ptr) return 0;
+              /* Check the return type is a pointer.
+                 On HP-UX 10 it is 'int'.  */
+              *localtime_r (0, 0);]])
+         ],
+         [gl_cv_time_r_posix=yes],
+         [gl_cv_time_r_posix=no])
+      ])
+    if test $gl_cv_time_r_posix = yes; then
+      REPLACE_LOCALTIME_R=0
+    else
+      REPLACE_LOCALTIME_R=1
+    fi
   else
-    REPLACE_LOCALTIME_R=1
+    HAVE_LOCALTIME_R=0
+  fi
+  if test $HAVE_LOCALTIME_R = 0 || test $REPLACE_LOCALTIME_R = 1; then
     AC_LIBOBJ([time_r])
     gl_PREREQ_TIME_R
   fi
index 733c9695b72586df787d6ce71bd01e8e34e1dc94..bfc208bfa2f025028941c460daeaa575ee51ee3c 100644 (file)
@@ -32,6 +32,7 @@ time.h: time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
              -e 's|@''GNULIB_STRPTIME''@|$(GNULIB_STRPTIME)|g' \
              -e 's|@''GNULIB_TIMEGM''@|$(GNULIB_TIMEGM)|g' \
              -e 's|@''GNULIB_TIME_R''@|$(GNULIB_TIME_R)|g' \
+             -e 's|@''HAVE_LOCALTIME_R''@|$(HAVE_LOCALTIME_R)|g' \
              -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \
              -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \
              -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \