# HG changeset patch # User Paul Eggert # Date 1157755705 0 # Node ID 4be2c469b3187410e832ef13913df802a73e9ebf # Parent 09d34e7dc0d8c190e77f76761cb3f0c66aae8f03 * config/srclist.txt: Temporarily comment out mktime.c until glibc bug 2821 is fixed. * lib/mktime.c (guess_time_tm): Fix bug where mktime returned the maximum time_t value rather than (time_t) -1. Problem originally reported by William Bardwell . * m4/mktime.m4 (AC_FUNC_MKTIME): Sync from Autoconf. Check for unistd.h too, since Autoconf doesn't assume POSIX. Also: 2006-09-08 Paul Eggert Add year_2050_test to catch glibc bug 2821 . 2006-08-15 Paul Eggert Prefer #ifdef to #if. 2006-04-02 Paul Eggert Return from 'main' instead of calling 'exit'. diff --git a/config/ChangeLog b/config/ChangeLog --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,8 @@ +2006-09-08 Paul Eggert + + * srclist.txt: Temporarily comment out mktime.c until glibc bug + 2821 is fixed. + 2006-09-04 Karl Berry * srclist.txt (signed.m4, gettext.m4): changes not propagated diff --git a/config/srclist.txt b/config/srclist.txt --- a/config/srclist.txt +++ b/config/srclist.txt @@ -1,4 +1,4 @@ -# $Id: srclist.txt,v 1.137 2006-09-04 12:45:56 karl Exp $ +# $Id: srclist.txt,v 1.138 2006-09-08 22:48:25 eggert Exp $ # Files for which we are not the source. See ./srclistvars.sh for the # variable definitions. @@ -195,7 +195,8 @@ $LIBCSRC/stdlib/strtoul.c lib gpl $LIBCSRC/string/strtok_r.c lib gpl $LIBCSRC/string/memmem.c lib gpl -$LIBCSRC/time/mktime.c lib gpl +# http://sourceware.org/bugzilla/show_bug.cgi?id=2821 +#$LIBCSRC/time/mktime.c lib gpl # # http://sourceware.org/bugzilla/show_bug.cgi?id=1439 diff --git a/lib/ChangeLog b/lib/ChangeLog --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,10 @@ 2006-09-08 Paul Eggert + * mktime.c (guess_time_tm): Fix bug where mktime + returned the maximum time_t value rather than (time_t) -1. + Problem originally reported by William Bardwell + . + * isapipe.h (HAVE_FIFO_PIPES) [!defined HAVE_FIFO_PIPES]: Moved to here ... * isapipe.c (HAVE_FIFO_PIPES) [!defined HAVE_FIFO_PIPES]: diff --git a/lib/mktime.c b/lib/mktime.c --- a/lib/mktime.c +++ b/lib/mktime.c @@ -1,5 +1,5 @@ /* Convert a `struct tm' to a time_t value. - Copyright (C) 1993-1999, 2002-2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1993-1999, 2002-2004, 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Paul Eggert (eggert@twinsun.com). @@ -215,10 +215,11 @@ /* Overflow occurred one way or another. Return the nearest result that is actually in range, except don't report a zero difference if the actual difference is nonzero, as that would cause a false - match. */ + match; and don't oscillate between two values, as that would + confuse the spring-forward gap detector. */ return (*t < TIME_T_MIDPOINT - ? TIME_T_MIN + (*t == TIME_T_MIN) - : TIME_T_MAX - (*t == TIME_T_MAX)); + ? (*t <= TIME_T_MIN + 1 ? *t + 1 : TIME_T_MIN) + : (TIME_T_MAX - 1 <= *t ? *t - 1 : TIME_T_MAX)); } /* Use CONVERT to convert *T to a broken down time in *TP. diff --git a/m4/ChangeLog b/m4/ChangeLog --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,19 @@ +2006-09-08 Paul Eggert + + * mktime.m4 (AC_FUNC_MKTIME): Sync from Autoconf. + Check for unistd.h too, since Autoconf doesn't assume POSIX. + Also: + + 2006-09-08 Paul Eggert + Add year_2050_test to catch glibc bug 2821 + . + + 2006-08-15 Paul Eggert + Prefer #ifdef to #if. + + 2006-04-02 Paul Eggert + Return from 'main' instead of calling 'exit'. + 2006-09-08 Jim Meyering Avoid new build failure on FreeBSD 6.0. diff --git a/m4/mktime.m4 b/m4/mktime.m4 --- a/m4/mktime.m4 +++ b/m4/mktime.m4 @@ -1,29 +1,29 @@ -#serial 7 -dnl Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. +#serial 8 +dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Jim Meyering. -# Redefine AC_FUNC_MKTIME, to fix a bug in Autoconf 2.57 and earlier. -# This redefinition can be removed once a new version of Autoconf comes out. +# Redefine AC_FUNC_MKTIME, to fix a bug in Autoconf 2.60a and earlier. +# This redefinition can be removed once a new version of Autoconf is assumed. # The redefinition is taken from -# . +# . # AC_FUNC_MKTIME # -------------- AC_DEFUN([AC_FUNC_MKTIME], [AC_REQUIRE([AC_HEADER_TIME])dnl -AC_CHECK_HEADERS_ONCE(sys/time.h) +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. */ -#if TIME_WITH_SYS_TIME +#ifdef TIME_WITH_SYS_TIME # include # include #else -# if HAVE_SYS_TIME_H +# ifdef HAVE_SYS_TIME_H # include # else # include @@ -31,9 +31,12 @@ #endif #include -#include -#if !HAVE_ALARM +#ifdef HAVE_UNISTD_H +# include +#endif + +#ifndef HAVE_ALARM # define alarm(X) /* empty */ #endif @@ -50,9 +53,9 @@ }; #define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0])) -/* Fail if mktime fails to convert a date in the spring-forward gap. +/* Return 0 if mktime fails to convert a date in the spring-forward gap. Based on a problem report from Andreas Jaeger. */ -static void +static int spring_forward_gap () { /* glibc (up to about 1998-10-07) failed this test. */ @@ -71,29 +74,27 @@ tm.tm_min = 0; tm.tm_sec = 0; tm.tm_isdst = -1; - if (mktime (&tm) == (time_t)-1) - exit (1); + return mktime (&tm) != (time_t) -1; } -static void +static int mktime_test1 (now) time_t now; { struct tm *lt; - if ((lt = localtime (&now)) && mktime (lt) != now) - exit (1); + return ! (lt = localtime (&now)) || mktime (lt) == now; } -static void +static int mktime_test (now) time_t now; { - mktime_test1 (now); - mktime_test1 ((time_t) (time_t_max - now)); - mktime_test1 ((time_t) (time_t_min + now)); + return (mktime_test1 (now) + && mktime_test1 ((time_t) (time_t_max - now)) + && mktime_test1 ((time_t) (time_t_min + now))); } -static void +static int irix_6_4_bug () { /* Based on code from Ariel Faigon. */ @@ -106,11 +107,10 @@ tm.tm_sec = 0; tm.tm_isdst = -1; mktime (&tm); - if (tm.tm_mon != 2 || tm.tm_mday != 31) - exit (1); + return tm.tm_mon == 2 && tm.tm_mday == 31; } -static void +static int bigtime_test (j) int j; { @@ -132,8 +132,39 @@ && lt->tm_wday == tm.tm_wday && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst) == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst)))) - exit (1); + return 0; } + 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 @@ -160,18 +191,20 @@ putenv (tz_strings[i]); for (t = 0; t <= time_t_max - delta; t += delta) - mktime_test (t); - mktime_test ((time_t) 1); - mktime_test ((time_t) (60 * 60)); - mktime_test ((time_t) (60 * 60 * 24)); + if (! mktime_test (t)) + return 1; + if (! (mktime_test ((time_t) 1) + && mktime_test ((time_t) (60 * 60)) + && mktime_test ((time_t) (60 * 60 * 24)))) + return 1; for (j = 1; 0 < j; j *= 2) - bigtime_test (j); - bigtime_test (j - 1); + if (! bigtime_test (j)) + return 1; + if (! bigtime_test (j - 1)) + return 1; } - irix_6_4_bug (); - spring_forward_gap (); - exit (0); + return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ()); }]])], [ac_cv_func_working_mktime=yes], [ac_cv_func_working_mktime=no],