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