time_rz.m4 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. dnl Time zone functions: tzalloc, localtime_rz, etc.
  2. dnl Copyright (C) 2015-2023 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. dnl Written by Paul Eggert.
  7. AC_DEFUN([gl_TIME_RZ],
  8. [
  9. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  10. AC_REQUIRE([gl_TIME_H_DEFAULTS])
  11. AC_REQUIRE([AC_STRUCT_TIMEZONE])
  12. # On Mac OS X 10.6, localtime loops forever with some time_t values.
  13. # See Bug#27706, Bug#27736, and
  14. # https://lists.gnu.org/r/bug-gnulib/2017-07/msg00142.html
  15. AC_CACHE_CHECK([whether localtime works even near extrema],
  16. [gl_cv_func_localtime_works],
  17. [gl_cv_func_localtime_works=yes
  18. AC_RUN_IFELSE(
  19. [AC_LANG_PROGRAM(
  20. [[#include <stdlib.h>
  21. #include <string.h>
  22. #include <unistd.h>
  23. #include <time.h>
  24. ]], [[
  25. time_t t = -67768038400666600;
  26. struct tm *tm;
  27. char *tz = getenv ("TZ");
  28. if (! (tz && strcmp (tz, "QQQ0") == 0))
  29. return 0;
  30. alarm (2);
  31. tm = localtime (&t);
  32. /* Use TM and *TM to suppress over-optimization. */
  33. return tm && tm->tm_isdst;
  34. ]])],
  35. [(TZ=QQQ0 ./conftest$EXEEXT) >/dev/null 2>&1 ||
  36. gl_cv_func_localtime_works=no],
  37. [],
  38. [gl_cv_func_localtime_works="guessing yes"])])
  39. if test "$gl_cv_func_localtime_works" = no; then
  40. AC_DEFINE([HAVE_LOCALTIME_INFLOOP_BUG], 1,
  41. [Define if localtime-like functions can loop forever on
  42. extreme arguments.])
  43. fi
  44. AC_CHECK_TYPES([timezone_t], [], [], [[#include <time.h>]])
  45. if test "$ac_cv_type_timezone_t" = yes; then
  46. HAVE_TIMEZONE_T=1
  47. fi
  48. ])