Blame m4/sys_time_h.m4

Packit aea12f
# Configure a replacement for <sys/time.h>.
Packit aea12f
# serial 9
Packit aea12f
Packit Service 991b93
# Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc.
Packit aea12f
# This file is free software; the Free Software Foundation
Packit aea12f
# gives unlimited permission to copy and/or distribute it,
Packit aea12f
# with or without modifications, as long as this notice is preserved.
Packit aea12f
Packit aea12f
# Written by Paul Eggert and Martin Lambers.
Packit aea12f
Packit aea12f
AC_DEFUN([gl_HEADER_SYS_TIME_H],
Packit aea12f
[
Packit aea12f
  dnl Use AC_REQUIRE here, so that the REPLACE_GETTIMEOFDAY=0 statement
Packit aea12f
  dnl below is expanded once only, before all REPLACE_GETTIMEOFDAY=1
Packit aea12f
  dnl statements that occur in other macros.
Packit aea12f
  AC_REQUIRE([gl_HEADER_SYS_TIME_H_BODY])
Packit aea12f
])
Packit aea12f
Packit aea12f
AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
Packit aea12f
[
Packit aea12f
  AC_REQUIRE([AC_C_RESTRICT])
Packit aea12f
  AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
Packit aea12f
  AC_CHECK_HEADERS_ONCE([sys/time.h])
Packit aea12f
  gl_CHECK_NEXT_HEADERS([sys/time.h])
Packit aea12f
Packit aea12f
  if test $ac_cv_header_sys_time_h != yes; then
Packit aea12f
    HAVE_SYS_TIME_H=0
Packit aea12f
  fi
Packit aea12f
Packit aea12f
  dnl On native Windows with MSVC, 'struct timeval' is defined in <winsock2.h>
Packit aea12f
  dnl only. So include that header in the list.
Packit aea12f
  gl_PREREQ_SYS_H_WINSOCK2
Packit aea12f
  AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
Packit aea12f
    [AC_COMPILE_IFELSE(
Packit aea12f
       [AC_LANG_PROGRAM(
Packit aea12f
          [[#if HAVE_SYS_TIME_H
Packit aea12f
             #include <sys/time.h>
Packit aea12f
            #endif
Packit aea12f
            #include <time.h>
Packit aea12f
            #if HAVE_WINSOCK2_H
Packit aea12f
            # include <winsock2.h>
Packit aea12f
            #endif
Packit aea12f
          ]],
Packit aea12f
          [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
Packit aea12f
       [gl_cv_sys_struct_timeval=yes],
Packit aea12f
       [gl_cv_sys_struct_timeval=no])
Packit aea12f
    ])
Packit aea12f
  if test $gl_cv_sys_struct_timeval != yes; then
Packit aea12f
    HAVE_STRUCT_TIMEVAL=0
Packit aea12f
  else
Packit aea12f
    dnl On native Windows with a 64-bit 'time_t', 'struct timeval' is defined
Packit aea12f
    dnl (in <sys/time.h> and <winsock2.h> for mingw64, in <winsock2.h> only
Packit aea12f
    dnl for MSVC) with a tv_sec field of type 'long' (32-bit!), which is
Packit aea12f
    dnl smaller than the 'time_t' type mandated by POSIX.
Packit aea12f
    dnl On OpenBSD 5.1 amd64, tv_sec is 64 bits and time_t 32 bits, but
Packit aea12f
    dnl that is good enough.
Packit aea12f
    AC_CACHE_CHECK([for wide-enough struct timeval.tv_sec member],
Packit aea12f
      [gl_cv_sys_struct_timeval_tv_sec],
Packit aea12f
      [AC_COMPILE_IFELSE(
Packit aea12f
         [AC_LANG_PROGRAM(
Packit aea12f
            [[#if HAVE_SYS_TIME_H
Packit aea12f
               #include <sys/time.h>
Packit aea12f
              #endif
Packit aea12f
              #include <time.h>
Packit aea12f
              #if HAVE_WINSOCK2_H
Packit aea12f
              # include <winsock2.h>
Packit aea12f
              #endif
Packit aea12f
            ]],
Packit aea12f
            [[static struct timeval x;
Packit aea12f
              typedef int verify_tv_sec_type[
Packit aea12f
                sizeof (time_t) <= sizeof x.tv_sec ? 1 : -1
Packit aea12f
              ];
Packit aea12f
            ]])],
Packit aea12f
         [gl_cv_sys_struct_timeval_tv_sec=yes],
Packit aea12f
         [gl_cv_sys_struct_timeval_tv_sec=no])
Packit aea12f
      ])
Packit aea12f
    if test $gl_cv_sys_struct_timeval_tv_sec != yes; then
Packit aea12f
      REPLACE_STRUCT_TIMEVAL=1
Packit aea12f
    fi
Packit aea12f
  fi
Packit aea12f
Packit aea12f
  dnl Check for declarations of anything we want to poison if the
Packit aea12f
  dnl corresponding gnulib module is not in use.
Packit aea12f
  gl_WARN_ON_USE_PREPARE([[
Packit aea12f
#if HAVE_SYS_TIME_H
Packit aea12f
# include <sys/time.h>
Packit aea12f
#endif
Packit aea12f
#include <time.h>
Packit aea12f
    ]], [gettimeofday])
Packit aea12f
])
Packit aea12f
Packit aea12f
AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR],
Packit aea12f
[
Packit aea12f
  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
Packit aea12f
  AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
Packit aea12f
  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
Packit aea12f
  dnl Define it also as a C macro, for the benefit of the unit tests.
Packit aea12f
  gl_MODULE_INDICATOR_FOR_TESTS([$1])
Packit aea12f
])
Packit aea12f
Packit aea12f
AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS],
Packit aea12f
[
Packit aea12f
  GNULIB_GETTIMEOFDAY=0;     AC_SUBST([GNULIB_GETTIMEOFDAY])
Packit aea12f
  dnl Assume POSIX behavior unless another module says otherwise.
Packit aea12f
  HAVE_GETTIMEOFDAY=1;       AC_SUBST([HAVE_GETTIMEOFDAY])
Packit aea12f
  HAVE_STRUCT_TIMEVAL=1;     AC_SUBST([HAVE_STRUCT_TIMEVAL])
Packit aea12f
  HAVE_SYS_TIME_H=1;         AC_SUBST([HAVE_SYS_TIME_H])
Packit aea12f
  REPLACE_GETTIMEOFDAY=0;    AC_SUBST([REPLACE_GETTIMEOFDAY])
Packit aea12f
  REPLACE_STRUCT_TIMEVAL=0;  AC_SUBST([REPLACE_STRUCT_TIMEVAL])
Packit aea12f
])