X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=m4%2Fmktime.m4;h=5faf3935e97c57d0baa74b7622e94e699e4370c5;hb=e9c57721db5e7cf2a19d93761d8c13e0c9701953;hp=6df253b36f8ae4572b3b653dd231b6fd8c5f9e48;hpb=2ad45ed8270dc07ce8843ec964e60bf4914eb0b0;p=gnulib.git diff --git a/m4/mktime.m4 b/m4/mktime.m4 index 6df253b36..5faf3935e 100644 --- a/m4/mktime.m4 +++ b/m4/mktime.m4 @@ -1,37 +1,32 @@ -#serial 1000 - -dnl From Paul Eggert -dnl Check for a working mktime. -dnl This is a preview of what should appear in the next public autoconf release. - -dnl Override any existing definition. -undefine([AC_FUNC_MKTIME]) - -AC_DEFUN(AC_FUNC_MKTIME, -[AC_REQUIRE([AC_HEADER_TIME])dnl -AC_CHECK_HEADERS(sys/time.h unistd.h) -AC_CHECK_FUNCS(alarm) +#serial 13 +dnl Copyright (C) 2002, 2003, 2005, 2006, 2007 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.61a 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_CHECK_HEADERS_ONCE(unistd.h) +AC_CHECK_FUNCS_ONCE(alarm) AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime, -[AC_TRY_RUN( -changequote(<<, >>)dnl -< -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif +[AC_RUN_IFELSE([AC_LANG_SOURCE( +[[/* Test program from Paul Eggert and Tony Leneis. */ +#include +#include +#include -#if HAVE_UNISTD_H +#ifdef HAVE_UNISTD_H # include #endif -#if !HAVE_ALARM +#ifndef HAVE_ALARM # define alarm(X) /* empty */ #endif @@ -39,20 +34,21 @@ changequote(<<, >>)dnl #undef putenv static time_t time_t_max; +static time_t time_t_min; /* Values we'll use to set the TZ environment variable. */ -static const char *const tz_strings[] = { - (const char *) 0, "TZ=GMT0", "TZ=JST-9", +static char *tz_strings[] = { + (char *) 0, "TZ=GMT0", "TZ=JST-9", "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00" }; #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) */ + /* glibc (up to about 1998-10-07) failed this test. */ struct tm tm; /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0" @@ -68,23 +64,27 @@ spring_forward_gap () 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 -mktime_test (now) +static int +mktime_test1 (now) time_t now; { struct tm *lt; - if ((lt = localtime (&now)) && mktime (lt) != now) - exit (1); - now = time_t_max - now; - if ((lt = localtime (&now)) && mktime (lt) != now) - exit (1); + return ! (lt = localtime (&now)) || mktime (lt) == now; +} + +static int +mktime_test (now) + time_t 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. */ @@ -97,11 +97,10 @@ irix_6_4_bug () 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; { @@ -123,8 +122,39 @@ bigtime_test (j) && 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 @@ -138,9 +168,15 @@ main () isn't worth using anyway. */ alarm (60); - for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2) - continue; - time_t_max--; + for (;;) + { + t = (time_t_max << 1) + 1; + if (t <= time_t_max) + break; + time_t_max = t; + } + time_t_min = - ((time_t) ~ (time_t) 0 == (time_t) -1) - time_t_max; + delta = time_t_max / 997; /* a suitable prime number */ for (i = 0; i < N_STRINGS; i++) { @@ -148,23 +184,44 @@ main () putenv (tz_strings[i]); for (t = 0; t <= time_t_max - delta; t += delta) - mktime_test (t); - mktime_test ((time_t) 60 * 60); - mktime_test ((time_t) 60 * 60 * 24); - - for (j = 1; 0 < j; j *= 2) - bigtime_test (j); - bigtime_test (j - 1); + 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; ; j <<= 1) + if (! bigtime_test (j)) + return 1; + else if (INT_MAX / 2 < j) + break; + if (! bigtime_test (INT_MAX)) + return 1; } - irix_6_4_bug (); - spring_forward_gap (); - exit (0); -} ->>, -changequote([, ])dnl -ac_cv_func_working_mktime=yes, ac_cv_func_working_mktime=no, -ac_cv_func_working_mktime=no)]) + return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ()); +}]])], + [ac_cv_func_working_mktime=yes], + [ac_cv_func_working_mktime=no], + [ac_cv_func_working_mktime=no])]) if test $ac_cv_func_working_mktime = no; then - LIBOBJS="$LIBOBJS mktime.${ac_objext}" + AC_LIBOBJ([mktime]) fi +])# AC_FUNC_MKTIME + +AC_DEFUN([gl_FUNC_MKTIME], +[ + AC_FUNC_MKTIME + dnl Note: AC_FUNC_MKTIME does AC_LIBOBJ(mktime). + if test $ac_cv_func_working_mktime = no; then + AC_DEFINE(mktime, rpl_mktime, + [Define to rpl_mktime if the replacement function should be used.]) + gl_PREREQ_MKTIME + fi +]) + +# Prerequisites of lib/mktime.c. +AC_DEFUN([gl_PREREQ_MKTIME], +[ + AC_REQUIRE([AC_C_INLINE]) ])