3 # Copyright (C) 2001-2003, 2005, 2007, 2009-2020 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
10 AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
12 AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
13 AC_REQUIRE([AC_C_RESTRICT])
14 AC_REQUIRE([AC_CANONICAL_HOST])
15 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
16 AC_CHECK_FUNCS_ONCE([gettimeofday])
18 gl_gettimeofday_timezone=void
19 if test $ac_cv_func_gettimeofday != yes; then
22 AC_CACHE_CHECK([for gettimeofday with POSIX signature],
23 [gl_cv_func_gettimeofday_posix_signature],
26 [[#include <sys/time.h>
28 int gettimeofday (struct timeval *restrict, void *restrict);
30 [[/* glibc uses struct timezone * rather than the POSIX void *
31 if _GNU_SOURCE is defined. However, since the only portable
32 use of gettimeofday uses NULL as the second parameter, and
33 since the glibc definition is actually more typesafe, it is
34 not worth wrapping this to get a compliant signature. */
35 int (*f) (struct timeval *restrict, void *restrict)
38 return !(x | c.tv_sec | c.tv_usec);
40 [gl_cv_func_gettimeofday_posix_signature=yes],
43 [[#include <sys/time.h>
44 int gettimeofday (struct timeval *restrict, struct timezone *restrict);
46 [gl_cv_func_gettimeofday_posix_signature=almost],
47 [gl_cv_func_gettimeofday_posix_signature=no])])])
48 if test $gl_cv_func_gettimeofday_posix_signature = almost; then
49 gl_gettimeofday_timezone='struct timezone'
50 elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
51 REPLACE_GETTIMEOFDAY=1
53 dnl If we override 'struct timeval', we also have to override gettimeofday.
54 if test $REPLACE_STRUCT_TIMEVAL = 1; then
55 REPLACE_GETTIMEOFDAY=1
57 dnl On mingw, the original gettimeofday has only a precision of 15.6
58 dnl milliseconds. So override it.
60 mingw*) REPLACE_GETTIMEOFDAY=1 ;;
63 AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone],
64 [Define this to 'void' or 'struct timezone' to match the system's
65 declaration of the second argument to gettimeofday.])
68 # Prerequisites of lib/gettimeofday.c.
69 AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [:])