time_r.m4 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. dnl Reentrant time functions: localtime_r, gmtime_r.
  2. dnl Copyright (C) 2003, 2006-2021 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_R],
  8. [
  9. dnl Persuade glibc and Solaris <time.h> to declare localtime_r.
  10. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  11. AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
  12. AC_REQUIRE([AC_C_RESTRICT])
  13. dnl Some systems don't declare localtime_r() and gmtime_r() if _REENTRANT is
  14. dnl not defined.
  15. AC_CHECK_DECLS([localtime_r], [], [],
  16. [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
  17. gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
  18. been included before. */
  19. #if defined __MINGW32__
  20. # include <unistd.h>
  21. #endif
  22. #include <time.h>
  23. ]])
  24. if test $ac_cv_have_decl_localtime_r = no; then
  25. HAVE_DECL_LOCALTIME_R=0
  26. fi
  27. AC_CHECK_FUNCS_ONCE([localtime_r])
  28. if test $ac_cv_func_localtime_r = yes; then
  29. HAVE_LOCALTIME_R=1
  30. AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
  31. [gl_cv_time_r_posix],
  32. [AC_COMPILE_IFELSE(
  33. [AC_LANG_PROGRAM(
  34. [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
  35. gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
  36. been included before. */
  37. #if defined __MINGW32__
  38. # include <unistd.h>
  39. #endif
  40. #include <time.h>
  41. ]],
  42. [[/* We don't need to append 'restrict's to the argument types,
  43. even though the POSIX signature has the 'restrict's,
  44. since C99 says they can't affect type compatibility. */
  45. struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r;
  46. if (ptr) return 0;
  47. /* Check the return type is a pointer.
  48. On HP-UX 10 it is 'int'. */
  49. *localtime_r (0, 0);]])
  50. ],
  51. [gl_cv_time_r_posix=yes],
  52. [gl_cv_time_r_posix=no])
  53. ])
  54. if test $gl_cv_time_r_posix = yes; then
  55. REPLACE_LOCALTIME_R=0
  56. else
  57. REPLACE_LOCALTIME_R=1
  58. fi
  59. else
  60. HAVE_LOCALTIME_R=0
  61. dnl On mingw, localtime_r() is defined as an inline function; use through a
  62. dnl direct function call works but the use as a function pointer leads to a
  63. dnl link error.
  64. AC_CACHE_CHECK([whether localtime_r exists as an inline function],
  65. [gl_cv_func_localtime_r_inline],
  66. [AC_LINK_IFELSE(
  67. [AC_LANG_PROGRAM(
  68. [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
  69. gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
  70. been included before. */
  71. #if defined __MINGW32__
  72. # include <unistd.h>
  73. #endif
  74. #include <time.h>
  75. ]],
  76. [[time_t a;
  77. struct tm r;
  78. localtime_r (&a, &r);
  79. ]])
  80. ],
  81. [gl_cv_func_localtime_r_inline=yes],
  82. [gl_cv_func_localtime_r_inline=no])
  83. ])
  84. if test $gl_cv_func_localtime_r_inline = yes; then
  85. REPLACE_LOCALTIME_R=1
  86. fi
  87. fi
  88. ])
  89. # Prerequisites of lib/time_r.c.
  90. AC_DEFUN([gl_PREREQ_TIME_R], [
  91. :
  92. ])