Blame m4/sys_time_h.m4

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