* modules/gettime (Depends-on): Add extensions module.
[gnulib.git] / m4 / timespec.m4
1 #serial 12
2
3 # Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006 Free Software
4 # Foundation, Inc.
5
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
9
10 dnl From Jim Meyering
11
12 AC_DEFUN([gl_TIMESPEC],
13 [
14   AC_LIBSOURCES([timespec.h])
15
16   dnl Prerequisites of lib/timespec.h.
17   AC_REQUIRE([AC_C_INLINE])
18   AC_REQUIRE([AC_HEADER_TIME])
19   AC_CHECK_HEADERS_ONCE(sys/time.h)
20   gl_CHECK_TYPE_STRUCT_TIMESPEC
21
22   dnl Persuade glibc and Solaris <time.h> to declare nanosleep.
23   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
24
25   AC_CHECK_DECLS(nanosleep, , , [#include <time.h>])
26 ])
27
28 dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
29 dnl in time.h or sys/time.h.
30
31 AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
32 [
33   dnl Persuade pedantic Solaris to declare struct timespec.
34   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
35
36   AC_REQUIRE([AC_HEADER_TIME])
37   AC_CHECK_HEADERS_ONCE(sys/time.h)
38   AC_CACHE_CHECK([for struct timespec], fu_cv_sys_struct_timespec,
39     [AC_TRY_COMPILE(
40       [
41 #      if TIME_WITH_SYS_TIME
42 #       include <sys/time.h>
43 #       include <time.h>
44 #      else
45 #       if HAVE_SYS_TIME_H
46 #        include <sys/time.h>
47 #       else
48 #        include <time.h>
49 #       endif
50 #      endif
51       ],
52       [static struct timespec x; x.tv_sec = x.tv_nsec;],
53       fu_cv_sys_struct_timespec=yes,
54       fu_cv_sys_struct_timespec=no)
55     ])
56
57   if test $fu_cv_sys_struct_timespec = yes; then
58     AC_DEFINE(HAVE_STRUCT_TIMESPEC, 1,
59               [Define if struct timespec is declared in <time.h>. ])
60   fi
61 ])