gnulib: update to 776af40e0
[deliverable/binutils-gdb.git] / gnulib / import / m4 / gettimeofday.m4
CommitLineData
9c9d63b1 1# serial 28
4a626d0a 2
9c9d63b1 3# Copyright (C) 2001-2003, 2005, 2007, 2009-2021 Free Software Foundation, Inc.
4a626d0a
PA
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[
c0c3707f 12 AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
4a626d0a 13 AC_REQUIRE([AC_C_RESTRICT])
c0c3707f 14 AC_REQUIRE([AC_CANONICAL_HOST])
4a626d0a 15 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
4a626d0a
PA
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
4a626d0a
PA
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
c0c3707f
CB
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
4a626d0a
PA
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
4a626d0a 68# Prerequisites of lib/gettimeofday.c.
c0c3707f 69AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [:])
This page took 0.402022 seconds and 4 git commands to generate.