Ensure we use gnulib mktime rather than glibc's mktime, on hosts
[gnulib.git] / m4 / timespec.m4
1 #serial 6
2
3 dnl From Jim Meyering
4
5 AC_DEFUN([gl_TIMESPEC],
6 [
7   dnl Prerequisites of lib/timespec.h.
8   AC_REQUIRE([AC_HEADER_TIME])
9   AC_CHECK_HEADERS_ONCE(sys/time.h)
10   jm_CHECK_TYPE_STRUCT_TIMESPEC
11   AC_STRUCT_ST_MTIM_NSEC
12
13   dnl Persuade glibc <time.h> to declare nanosleep().
14   AC_REQUIRE([AC_GNU_SOURCE])
15
16   AC_CHECK_DECLS(nanosleep, , , [#include <time.h>])
17 ])
18
19 dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
20 dnl in time.h or sys/time.h.
21
22 AC_DEFUN([jm_CHECK_TYPE_STRUCT_TIMESPEC],
23 [
24   AC_REQUIRE([AC_HEADER_TIME])
25   AC_CHECK_HEADERS_ONCE(sys/time.h)
26   AC_CACHE_CHECK([for struct timespec], fu_cv_sys_struct_timespec,
27     [AC_TRY_COMPILE(
28       [
29 #      if TIME_WITH_SYS_TIME
30 #       include <sys/time.h>
31 #       include <time.h>
32 #      else
33 #       if HAVE_SYS_TIME_H
34 #        include <sys/time.h>
35 #       else
36 #        include <time.h>
37 #       endif
38 #      endif
39       ],
40       [static struct timespec x; x.tv_sec = x.tv_nsec;],
41       fu_cv_sys_struct_timespec=yes,
42       fu_cv_sys_struct_timespec=no)
43     ])
44
45   if test $fu_cv_sys_struct_timespec = yes; then
46     AC_DEFINE(HAVE_STRUCT_TIMESPEC, 1,
47               [Define if struct timespec is declared in <time.h>. ])
48   fi
49 ])