gettimeofday.m4 2.7 KB

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