4 dnl Check for the nanosleep function.
5 dnl If not found, use the supplied replacement.
8 # Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free Software
11 # This file is free software; the Free Software Foundation
12 # gives unlimited permission to copy and/or distribute it,
13 # with or without modifications, as long as this notice is preserved.
15 AC_DEFUN([gl_FUNC_NANOSLEEP],
17 dnl Persuade glibc and Solaris <time.h> to declare nanosleep.
18 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
20 AC_REQUIRE([AC_HEADER_TIME])
21 AC_REQUIRE([gl_CLOCK_TIME])
22 AC_CHECK_HEADERS_ONCE(sys/time.h)
24 nanosleep_save_libs=$LIBS
26 # Solaris 2.5.1 needs -lposix4 to get the nanosleep function.
27 # Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4.
28 AC_SEARCH_LIBS([nanosleep], [rt posix4],
29 [test "$ac_cv_search_nanosleep" = "none required" ||
30 LIB_NANOSLEEP=$ac_cv_search_nanosleep])
32 AC_CACHE_CHECK([for working nanosleep],
33 [gl_cv_func_nanosleep],
37 #if TIME_WITH_SYS_TIME
51 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
52 #define TYPE_MAXIMUM(t) \
53 ((t) (! TYPE_SIGNED (t) \
55 : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
58 check_for_SIGALRM (int sig)
67 static struct timespec ts_sleep;
68 static struct timespec ts_remaining;
69 static struct sigaction act;
70 act.sa_handler = check_for_SIGALRM;
71 sigemptyset (&act.sa_mask);
72 sigaction (SIGALRM, &act, NULL);
73 ts_sleep.tv_sec = TYPE_MAXIMUM (time_t);
74 ts_sleep.tv_nsec = 999999999;
76 if (nanosleep (&ts_sleep, &ts_remaining) == -1 && errno == EINTR
77 && TYPE_MAXIMUM (time_t) - 10 < ts_remaining.tv_sec)
81 [gl_cv_func_nanosleep=yes],
83 119) gl_cv_func_nanosleep='no (mishandles large arguments)';; dnl (
84 *) gl_cv_func_nanosleep=no;;
86 [gl_cv_func_nanosleep=cross-compiling])
88 if test "$gl_cv_func_nanosleep" != yes; then
89 if test "$gl_cv_func_nanosleep" = 'no (mishandles large arguments)'; then
90 AC_DEFINE([HAVE_BUG_BIG_NANOSLEEP], 1,
91 [Define to 1 if nanosleep mishandle large arguments.])
92 for ac_lib in $LIB_CLOCK_GETTIME; do
93 case " $LIB_NANOSLEEP " in
95 *) LIB_NANOSLEEP="$LIB_NANOSLEEP $ac_lib";;
100 AC_DEFINE(nanosleep, rpl_nanosleep,
101 [Define to rpl_nanosleep if the replacement function should be used.])
105 AC_SUBST([LIB_NANOSLEEP])
106 LIBS=$nanosleep_save_libs
109 # Prerequisites of lib/nanosleep.c.
110 AC_DEFUN([gl_PREREQ_NANOSLEEP],
112 AC_CHECK_FUNCS_ONCE(siginterrupt)
113 AC_CHECK_HEADERS_ONCE(sys/select.h)