|
Packit Service |
a2ae7a |
# serial 26
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
# Copyright (C) 2001-2003, 2005, 2007, 2009-2019 Free Software Foundation, Inc.
|
|
Packit Service |
a2ae7a |
# This file is free software; the Free Software Foundation
|
|
Packit Service |
a2ae7a |
# gives unlimited permission to copy and/or distribute it,
|
|
Packit Service |
a2ae7a |
# with or without modifications, as long as this notice is preserved.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
dnl From Jim Meyering.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
|
|
Packit Service |
a2ae7a |
[
|
|
Packit Service |
a2ae7a |
AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
|
|
Packit Service |
a2ae7a |
AC_REQUIRE([AC_C_RESTRICT])
|
|
Packit Service |
a2ae7a |
AC_REQUIRE([AC_CANONICAL_HOST])
|
|
Packit Service |
a2ae7a |
AC_REQUIRE([gl_HEADER_SYS_TIME_H])
|
|
Packit Service |
a2ae7a |
AC_CHECK_FUNCS_ONCE([gettimeofday])
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
gl_gettimeofday_timezone=void
|
|
Packit Service |
a2ae7a |
if test $ac_cv_func_gettimeofday != yes; then
|
|
Packit Service |
a2ae7a |
HAVE_GETTIMEOFDAY=0
|
|
Packit Service |
a2ae7a |
else
|
|
Packit Service |
a2ae7a |
gl_FUNC_GETTIMEOFDAY_CLOBBER
|
|
Packit Service |
a2ae7a |
AC_CACHE_CHECK([for gettimeofday with POSIX signature],
|
|
Packit Service |
a2ae7a |
[gl_cv_func_gettimeofday_posix_signature],
|
|
Packit Service |
a2ae7a |
[AC_COMPILE_IFELSE(
|
|
Packit Service |
a2ae7a |
[AC_LANG_PROGRAM(
|
|
Packit Service |
a2ae7a |
[[#include <sys/time.h>
|
|
Packit Service |
a2ae7a |
struct timeval c;
|
|
Packit Service |
a2ae7a |
int gettimeofday (struct timeval *restrict, void *restrict);
|
|
Packit Service |
a2ae7a |
]],
|
|
Packit Service |
a2ae7a |
[[/* glibc uses struct timezone * rather than the POSIX void *
|
|
Packit Service |
a2ae7a |
if _GNU_SOURCE is defined. However, since the only portable
|
|
Packit Service |
a2ae7a |
use of gettimeofday uses NULL as the second parameter, and
|
|
Packit Service |
a2ae7a |
since the glibc definition is actually more typesafe, it is
|
|
Packit Service |
a2ae7a |
not worth wrapping this to get a compliant signature. */
|
|
Packit Service |
a2ae7a |
int (*f) (struct timeval *restrict, void *restrict)
|
|
Packit Service |
a2ae7a |
= gettimeofday;
|
|
Packit Service |
a2ae7a |
int x = f (&c, 0);
|
|
Packit Service |
a2ae7a |
return !(x | c.tv_sec | c.tv_usec);
|
|
Packit Service |
a2ae7a |
]])],
|
|
Packit Service |
a2ae7a |
[gl_cv_func_gettimeofday_posix_signature=yes],
|
|
Packit Service |
a2ae7a |
[AC_COMPILE_IFELSE(
|
|
Packit Service |
a2ae7a |
[AC_LANG_PROGRAM(
|
|
Packit Service |
a2ae7a |
[[#include <sys/time.h>
|
|
Packit Service |
a2ae7a |
int gettimeofday (struct timeval *restrict, struct timezone *restrict);
|
|
Packit Service |
a2ae7a |
]])],
|
|
Packit Service |
a2ae7a |
[gl_cv_func_gettimeofday_posix_signature=almost],
|
|
Packit Service |
a2ae7a |
[gl_cv_func_gettimeofday_posix_signature=no])])])
|
|
Packit Service |
a2ae7a |
if test $gl_cv_func_gettimeofday_posix_signature = almost; then
|
|
Packit Service |
a2ae7a |
gl_gettimeofday_timezone='struct timezone'
|
|
Packit Service |
a2ae7a |
elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
|
|
Packit Service |
a2ae7a |
REPLACE_GETTIMEOFDAY=1
|
|
Packit Service |
a2ae7a |
fi
|
|
Packit Service |
a2ae7a |
dnl If we override 'struct timeval', we also have to override gettimeofday.
|
|
Packit Service |
a2ae7a |
if test $REPLACE_STRUCT_TIMEVAL = 1; then
|
|
Packit Service |
a2ae7a |
REPLACE_GETTIMEOFDAY=1
|
|
Packit Service |
a2ae7a |
fi
|
|
Packit Service |
a2ae7a |
dnl On mingw, the original gettimeofday has only a precision of 15.6
|
|
Packit Service |
a2ae7a |
dnl milliseconds. So override it.
|
|
Packit Service |
a2ae7a |
case "$host_os" in
|
|
Packit Service |
a2ae7a |
mingw*) REPLACE_GETTIMEOFDAY=1 ;;
|
|
Packit Service |
a2ae7a |
esac
|
|
Packit Service |
a2ae7a |
fi
|
|
Packit Service |
a2ae7a |
AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone],
|
|
Packit Service |
a2ae7a |
[Define this to 'void' or 'struct timezone' to match the system's
|
|
Packit Service |
a2ae7a |
declaration of the second argument to gettimeofday.])
|
|
Packit Service |
a2ae7a |
])
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
dnl See if gettimeofday clobbers the static buffer that localtime uses
|
|
Packit Service |
a2ae7a |
dnl for its return value. The gettimeofday function from Mac OS X 10.0.4
|
|
Packit Service |
a2ae7a |
dnl (i.e., Darwin 1.3.7) has this problem.
|
|
Packit Service |
a2ae7a |
dnl
|
|
Packit Service |
a2ae7a |
dnl If it does, then arrange to use gettimeofday and localtime only via
|
|
Packit Service |
a2ae7a |
dnl the wrapper functions that work around the problem.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
|
|
Packit Service |
a2ae7a |
[
|
|
Packit Service |
a2ae7a |
AC_REQUIRE([gl_HEADER_SYS_TIME_H])
|
|
Packit Service |
a2ae7a |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
|
|
Packit Service |
a2ae7a |
AC_REQUIRE([gl_LOCALTIME_BUFFER_DEFAULTS])
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
|
|
Packit Service |
a2ae7a |
[gl_cv_func_gettimeofday_clobber],
|
|
Packit Service |
a2ae7a |
[AC_RUN_IFELSE(
|
|
Packit Service |
a2ae7a |
[AC_LANG_PROGRAM(
|
|
Packit Service |
a2ae7a |
[[#include <string.h>
|
|
Packit Service |
a2ae7a |
#include <sys/time.h>
|
|
Packit Service |
a2ae7a |
#include <time.h>
|
|
Packit Service |
a2ae7a |
#include <stdlib.h>
|
|
Packit Service |
a2ae7a |
]],
|
|
Packit Service |
a2ae7a |
[[
|
|
Packit Service |
a2ae7a |
time_t t = 0;
|
|
Packit Service |
a2ae7a |
struct tm *lt;
|
|
Packit Service |
a2ae7a |
struct tm saved_lt;
|
|
Packit Service |
a2ae7a |
struct timeval tv;
|
|
Packit Service |
a2ae7a |
lt = localtime (&t);
|
|
Packit Service |
a2ae7a |
saved_lt = *lt;
|
|
Packit Service |
a2ae7a |
gettimeofday (&tv, NULL);
|
|
Packit Service |
a2ae7a |
return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
|
|
Packit Service |
a2ae7a |
]])],
|
|
Packit Service |
a2ae7a |
[gl_cv_func_gettimeofday_clobber=no],
|
|
Packit Service |
a2ae7a |
[gl_cv_func_gettimeofday_clobber=yes],
|
|
Packit Service |
a2ae7a |
[# When cross-compiling:
|
|
Packit Service |
a2ae7a |
case "$host_os" in
|
|
Packit Service |
a2ae7a |
# Guess all is fine on glibc systems.
|
|
Packit Service |
a2ae7a |
*-gnu* | gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
|
|
Packit Service |
a2ae7a |
# Guess all is fine on musl systems.
|
|
Packit Service |
a2ae7a |
*-musl*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
|
|
Packit Service |
a2ae7a |
# Guess no on native Windows.
|
|
Packit Service |
a2ae7a |
mingw*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
|
|
Packit Service |
a2ae7a |
# If we don't know, assume the worst.
|
|
Packit Service |
a2ae7a |
*) gl_cv_func_gettimeofday_clobber="guessing yes" ;;
|
|
Packit Service |
a2ae7a |
esac
|
|
Packit Service |
a2ae7a |
])])
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
case "$gl_cv_func_gettimeofday_clobber" in
|
|
Packit Service |
a2ae7a |
*yes)
|
|
Packit Service |
a2ae7a |
REPLACE_GETTIMEOFDAY=1
|
|
Packit Service |
a2ae7a |
AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1],
|
|
Packit Service |
a2ae7a |
[Define if gettimeofday clobbers the localtime buffer.])
|
|
Packit Service |
a2ae7a |
gl_LOCALTIME_BUFFER_NEEDED
|
|
Packit Service |
a2ae7a |
;;
|
|
Packit Service |
a2ae7a |
esac
|
|
Packit Service |
a2ae7a |
])
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
# Prerequisites of lib/gettimeofday.c.
|
|
Packit Service |
a2ae7a |
AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [:])
|