Debian Codegraph @

m4/gettimeofday.m4

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