| 1 |
# gettimeofday.m4 |
| 2 |
# serial 30 |
| 3 |
dnl Copyright (C) 2001-2003, 2005, 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 |
dnl From Jim Meyering. |
| 10 |
|
| 11 |
AC_DEFUN([gl_FUNC_GETTIMEOFDAY], |
| 12 |
[ |
| 13 |
AC_REQUIRE([gl_SYS_TIME_H_DEFAULTS]) |
| 14 |
AC_REQUIRE([AC_C_RESTRICT]) |
| 15 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 16 |
AC_REQUIRE([gl_SYS_TIME_H]) |
| 17 |
AC_CHECK_FUNCS_ONCE([gettimeofday]) |
| 18 |
|
| 19 |
gl_gettimeofday_timezone=void |
| 20 |
if test $ac_cv_func_gettimeofday != yes; then |
| 21 |
HAVE_GETTIMEOFDAY=0 |
| 22 |
else |
| 23 |
AC_CACHE_CHECK([for gettimeofday with POSIX signature], |
| 24 |
[gl_cv_func_gettimeofday_posix_signature], |
| 25 |
[AC_COMPILE_IFELSE( |
| 26 |
[AC_LANG_PROGRAM( |
| 27 |
[[#include <sys/time.h> |
| 28 |
struct timeval c; |
| 29 |
int gettimeofday (struct timeval *restrict, void *restrict); |
| 30 |
]], |
| 31 |
[[/* glibc uses struct timezone * rather than the POSIX void * |
| 32 |
if _GNU_SOURCE is defined. However, since the only portable |
| 33 |
use of gettimeofday uses NULL as the second parameter, and |
| 34 |
since the glibc definition is actually more typesafe, it is |
| 35 |
not worth wrapping this to get a compliant signature. */ |
| 36 |
int (*f) (struct timeval *restrict, void *restrict) |
| 37 |
= gettimeofday; |
| 38 |
int x = f (&c, 0); |
| 39 |
return !(x | c.tv_sec | c.tv_usec); |
| 40 |
]])], |
| 41 |
[gl_cv_func_gettimeofday_posix_signature=yes], |
| 42 |
[AC_COMPILE_IFELSE( |
| 43 |
[AC_LANG_PROGRAM( |
| 44 |
[[#include <sys/time.h> |
| 45 |
int gettimeofday (struct timeval *restrict, struct timezone *restrict); |
| 46 |
]])], |
| 47 |
[gl_cv_func_gettimeofday_posix_signature=almost], |
| 48 |
[gl_cv_func_gettimeofday_posix_signature=no])])]) |
| 49 |
if test $gl_cv_func_gettimeofday_posix_signature = almost; then |
| 50 |
gl_gettimeofday_timezone='struct timezone' |
| 51 |
elif test $gl_cv_func_gettimeofday_posix_signature != yes; then |
| 52 |
REPLACE_GETTIMEOFDAY=1 |
| 53 |
fi |
| 54 |
dnl If we override 'struct timeval', we also have to override gettimeofday. |
| 55 |
if test $REPLACE_STRUCT_TIMEVAL = 1; then |
| 56 |
REPLACE_GETTIMEOFDAY=1 |
| 57 |
fi |
| 58 |
dnl On mingw, the original gettimeofday has only a precision of 15.6 |
| 59 |
dnl milliseconds. So override it. |
| 60 |
case "$host_os" in |
| 61 |
mingw* | windows*) REPLACE_GETTIMEOFDAY=1 ;; |
| 62 |
esac |
| 63 |
fi |
| 64 |
AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone], |
| 65 |
[Define this to 'void' or 'struct timezone' to match the system's |
| 66 |
declaration of the second argument to gettimeofday.]) |
| 67 |
]) |
| 68 |
|
| 69 |
# Prerequisites of lib/gettimeofday.c. |
| 70 |
AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [:]) |