sys_time_h.m4 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Configure a replacement for <sys/time.h>.
  2. # serial 8
  3. # Copyright (C) 2007, 2009-2017 Free Software Foundation, Inc.
  4. # This file is free software; the Free Software Foundation
  5. # gives unlimited permission to copy and/or distribute it,
  6. # with or without modifications, as long as this notice is preserved.
  7. # Written by Paul Eggert and Martin Lambers.
  8. AC_DEFUN([gl_HEADER_SYS_TIME_H],
  9. [
  10. dnl Use AC_REQUIRE here, so that the REPLACE_GETTIMEOFDAY=0 statement
  11. dnl below is expanded once only, before all REPLACE_GETTIMEOFDAY=1
  12. dnl statements that occur in other macros.
  13. AC_REQUIRE([gl_HEADER_SYS_TIME_H_BODY])
  14. ])
  15. AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
  16. [
  17. AC_REQUIRE([AC_C_RESTRICT])
  18. AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
  19. AC_CHECK_HEADERS_ONCE([sys/time.h])
  20. gl_CHECK_NEXT_HEADERS([sys/time.h])
  21. if test $ac_cv_header_sys_time_h != yes; then
  22. HAVE_SYS_TIME_H=0
  23. fi
  24. dnl On native Windows with MSVC, 'struct timeval' is defined in <winsock2.h>
  25. dnl only. So include that header in the list.
  26. gl_PREREQ_SYS_H_WINSOCK2
  27. AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
  28. [AC_COMPILE_IFELSE(
  29. [AC_LANG_PROGRAM(
  30. [[#if HAVE_SYS_TIME_H
  31. #include <sys/time.h>
  32. #endif
  33. #include <time.h>
  34. #if HAVE_WINSOCK2_H
  35. # include <winsock2.h>
  36. #endif
  37. ]],
  38. [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
  39. [gl_cv_sys_struct_timeval=yes],
  40. [gl_cv_sys_struct_timeval=no])
  41. ])
  42. if test $gl_cv_sys_struct_timeval != yes; then
  43. HAVE_STRUCT_TIMEVAL=0
  44. else
  45. dnl On native Windows with a 64-bit 'time_t', 'struct timeval' is defined
  46. dnl (in <sys/time.h> and <winsock2.h> for mingw64, in <winsock2.h> only
  47. dnl for MSVC) with a tv_sec field of type 'long' (32-bit!), which is
  48. dnl smaller than the 'time_t' type mandated by POSIX.
  49. dnl On OpenBSD 5.1 amd64, tv_sec is 64 bits and time_t 32 bits, but
  50. dnl that is good enough.
  51. AC_CACHE_CHECK([for wide-enough struct timeval.tv_sec member],
  52. [gl_cv_sys_struct_timeval_tv_sec],
  53. [AC_COMPILE_IFELSE(
  54. [AC_LANG_PROGRAM(
  55. [[#if HAVE_SYS_TIME_H
  56. #include <sys/time.h>
  57. #endif
  58. #include <time.h>
  59. #if HAVE_WINSOCK2_H
  60. # include <winsock2.h>
  61. #endif
  62. ]],
  63. [[static struct timeval x;
  64. typedef int verify_tv_sec_type[
  65. sizeof (time_t) <= sizeof x.tv_sec ? 1 : -1
  66. ];
  67. ]])],
  68. [gl_cv_sys_struct_timeval_tv_sec=yes],
  69. [gl_cv_sys_struct_timeval_tv_sec=no])
  70. ])
  71. if test $gl_cv_sys_struct_timeval_tv_sec != yes; then
  72. REPLACE_STRUCT_TIMEVAL=1
  73. fi
  74. fi
  75. dnl Check for declarations of anything we want to poison if the
  76. dnl corresponding gnulib module is not in use.
  77. gl_WARN_ON_USE_PREPARE([[
  78. #if HAVE_SYS_TIME_H
  79. # include <sys/time.h>
  80. #endif
  81. #include <time.h>
  82. ]], [gettimeofday])
  83. ])
  84. AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR],
  85. [
  86. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  87. AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
  88. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  89. dnl Define it also as a C macro, for the benefit of the unit tests.
  90. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  91. ])
  92. AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS],
  93. [
  94. GNULIB_GETTIMEOFDAY=0; AC_SUBST([GNULIB_GETTIMEOFDAY])
  95. dnl Assume POSIX behavior unless another module says otherwise.
  96. HAVE_GETTIMEOFDAY=1; AC_SUBST([HAVE_GETTIMEOFDAY])
  97. HAVE_STRUCT_TIMEVAL=1; AC_SUBST([HAVE_STRUCT_TIMEVAL])
  98. HAVE_SYS_TIME_H=1; AC_SUBST([HAVE_SYS_TIME_H])
  99. HAVE_TIMEZONE_T=0; AC_SUBST([HAVE_TIMEZONE_T])
  100. REPLACE_GETTIMEOFDAY=0; AC_SUBST([REPLACE_GETTIMEOFDAY])
  101. REPLACE_STRUCT_TIMEVAL=0; AC_SUBST([REPLACE_STRUCT_TIMEVAL])
  102. ])