1# serial 29 2 3# Copyright (C) 2001-2003, 2005, 2007, 2009-2022 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. 7 8dnl From Jim Meyering. 9 10AC_DEFUN([gl_FUNC_GETTIMEOFDAY], 11[ 12 AC_REQUIRE([gl_SYS_TIME_H_DEFAULTS]) 13 AC_REQUIRE([AC_C_RESTRICT]) 14 AC_REQUIRE([AC_CANONICAL_HOST]) 15 AC_REQUIRE([gl_SYS_TIME_H]) 16 AC_CHECK_FUNCS_ONCE([gettimeofday]) 17 18 gl_gettimeofday_timezone=void 19 if test $ac_cv_func_gettimeofday != yes; then 20 HAVE_GETTIMEOFDAY=0 21 else 22 AC_CACHE_CHECK([for gettimeofday with POSIX signature], 23 [gl_cv_func_gettimeofday_posix_signature], 24 [AC_COMPILE_IFELSE( 25 [AC_LANG_PROGRAM( 26 [[#include <sys/time.h> 27 struct timeval c; 28 int gettimeofday (struct timeval *restrict, void *restrict); 29 ]], 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) 36 = gettimeofday; 37 int x = f (&c, 0); 38 return !(x | c.tv_sec | c.tv_usec); 39 ]])], 40 [gl_cv_func_gettimeofday_posix_signature=yes], 41 [AC_COMPILE_IFELSE( 42 [AC_LANG_PROGRAM( 43 [[#include <sys/time.h> 44int gettimeofday (struct timeval *restrict, struct timezone *restrict); 45 ]])], 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 52 fi 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 56 fi 57 dnl On mingw, the original gettimeofday has only a precision of 15.6 58 dnl milliseconds. So override it. 59 case "$host_os" in 60 mingw*) REPLACE_GETTIMEOFDAY=1 ;; 61 esac 62 fi 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.]) 66]) 67 68# Prerequisites of lib/gettimeofday.c. 69AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [:]) 70