autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

improve AC_FUNC_MKTIME to catch glibc bug 2821


From: Paul Eggert
Subject: improve AC_FUNC_MKTIME to catch glibc bug 2821
Date: Fri, 08 Sep 2006 15:37:46 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

I installed this:

2006-09-08  Paul Eggert  <address@hidden>

        * lib/autoconf/functions.m4 (AC_FUNC_MKTIME):  Add year_2050_test
        to catch glibc bug 2821
        <http://sourceware.org/bugzilla/show_bug.cgi?id=2821>.

        Merge from gnulib as follows: Use AC_CHECK_HEADERS_ONCE instead of
        AC_CHECK_HEADERS, and likewise for AC_CHECK_FUNCS_ONCE and
        AC_CHECK_FUNCS.  Don't check for stdlib.h, since we now
        assume C89.

--- lib/autoconf/functions.m4   15 Aug 2006 16:24:42 -0000      1.107
+++ lib/autoconf/functions.m4   8 Sep 2006 22:36:16 -0000       1.108
@@ -972,8 +972,8 @@ test $ac_cv_func_memcmp_working = no && 
 AN_FUNCTION([mktime], [AC_FUNC_MKTIME])
 AC_DEFUN([AC_FUNC_MKTIME],
 [AC_REQUIRE([AC_HEADER_TIME])dnl
-AC_CHECK_HEADERS(stdlib.h sys/time.h unistd.h)
-AC_CHECK_FUNCS(alarm)
+AC_CHECK_HEADERS_ONCE(sys/time.h unistd.h)
+AC_CHECK_FUNCS_ONCE(alarm)
 AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
 [AC_RUN_IFELSE([AC_LANG_SOURCE(
 [[/* Test program from Paul Eggert and Tony Leneis.  */
@@ -988,9 +988,7 @@ AC_CACHE_CHECK([for working mktime], ac_
 # endif
 #endif
 
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
+#include <stdlib.h>
 
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
@@ -1097,6 +1095,36 @@ bigtime_test (j)
   return 1;
 }
 
+static int
+year_2050_test ()
+{
+  /* The correct answer for 2050-02-01 00:00:00 in Pacific time,
+     ignoring leap seconds.  */
+  unsigned long int answer = 2527315200UL;
+
+  struct tm tm;
+  time_t t;
+  tm.tm_year = 2050 - 1900;
+  tm.tm_mon = 2 - 1;
+  tm.tm_mday = 1;
+  tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
+  tm.tm_isdst = -1;
+
+  /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
+     instead of "TZ=America/Vancouver" in order to detect the bug even
+     on systems that don't support the Olson extension, or don't have the
+     full zoneinfo tables installed.  */
+  putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
+
+  t = mktime (&tm);
+
+  /* Check that the result is either a failure, or close enough
+     to the correct answer that we can assume the discrepancy is
+     due to leap seconds.  */
+  return (t == (time_t) -1
+         || (0 < t && answer - 120 <= t && t <= answer + 120));
+}
+
 int
 main ()
 {
@@ -1134,7 +1162,7 @@ main ()
       if (! bigtime_test (j - 1))
        return 1;
     }
-  return ! (irix_6_4_bug () && spring_forward_gap ());
+  return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ());
 }]])],
               [ac_cv_func_working_mktime=yes],
               [ac_cv_func_working_mktime=no],




reply via email to

[Prev in Thread] Current Thread [Next in Thread]