3 # Copyright (C) 2001-2003, 2005, 2007, 2009-2017 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 gl_FUNC_GETTIMEOFDAY_CLOBBER
23 AC_CACHE_CHECK([for gettimeofday with POSIX signature],
24 [gl_cv_func_gettimeofday_posix_signature],
27 [[#include <sys/time.h>
29 int gettimeofday (struct timeval *restrict, void *restrict);
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)
39 return !(x | c.tv_sec | c.tv_usec);
41 [gl_cv_func_gettimeofday_posix_signature=yes],
44 [[#include <sys/time.h>
45 int gettimeofday (struct timeval *restrict, struct timezone *restrict);
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
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
58 dnl On mingw, the original gettimeofday has only a precision of 15.6
59 dnl milliseconds. So override it.
61 mingw*) REPLACE_GETTIMEOFDAY=1 ;;
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.])
70 dnl See if gettimeofday clobbers the static buffer that localtime uses
71 dnl for its return value. The gettimeofday function from Mac OS X 10.0.4
72 dnl (i.e., Darwin 1.3.7) has this problem.
74 dnl If it does, then arrange to use gettimeofday and localtime only via
75 dnl the wrapper functions that work around the problem.
77 AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
79 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
80 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
81 AC_REQUIRE([gl_LOCALTIME_BUFFER_DEFAULTS])
83 AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
84 [gl_cv_func_gettimeofday_clobber],
99 gettimeofday (&tv, NULL);
100 return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
102 [gl_cv_func_gettimeofday_clobber=no],
103 [gl_cv_func_gettimeofday_clobber=yes],
104 [# When cross-compiling:
106 # Guess all is fine on glibc systems.
107 *-gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
108 # Guess no on native Windows.
109 mingw*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
110 # If we don't know, assume the worst.
111 *) gl_cv_func_gettimeofday_clobber="guessing yes" ;;
115 case "$gl_cv_func_gettimeofday_clobber" in
117 REPLACE_GETTIMEOFDAY=1
118 AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1],
119 [Define if gettimeofday clobbers the localtime buffer.])
120 gl_LOCALTIME_BUFFER_NEEDED
125 # Prerequisites of lib/gettimeofday.c.
126 AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [:])