4 dnl Check for the nanosleep function.
5 dnl If not found, use the supplied replacement.
8 # Copyright (C) 1999-2001, 2003-2010 Free Software Foundation, Inc.
10 # This file is free software; the Free Software Foundation
11 # gives unlimited permission to copy and/or distribute it,
12 # with or without modifications, as long as this notice is preserved.
14 AC_DEFUN([gl_FUNC_NANOSLEEP],
16 dnl Persuade glibc and Solaris <time.h> to declare nanosleep.
17 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
19 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
20 AC_CHECK_HEADERS_ONCE([sys/time.h])
21 AC_REQUIRE([gl_FUNC_SELECT])
23 nanosleep_save_libs=$LIBS
25 # Solaris 2.5.1 needs -lposix4 to get the nanosleep function.
26 # Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4.
28 AC_SUBST([LIB_NANOSLEEP])
29 AC_SEARCH_LIBS([nanosleep], [rt posix4],
30 [test "$ac_cv_search_nanosleep" = "none required" ||
31 LIB_NANOSLEEP=$ac_cv_search_nanosleep])
32 if test "x$ac_cv_search_nanosleep" != xno; then
33 dnl The system has a nanosleep function.
35 AC_REQUIRE([gl_MULTIARCH])
36 if test $APPLE_UNIVERSAL_BUILD = 1; then
37 # A universal build on Apple MacOS X platforms.
38 # The test result would be 'no (mishandles large arguments)' in 64-bit
39 # mode but 'yes' in 32-bit mode. But we need a configuration result that
40 # is valid in both modes.
41 gl_cv_func_nanosleep='no (mishandles large arguments)'
44 AC_CACHE_CHECK([for working nanosleep],
45 [gl_cv_func_nanosleep],
57 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
58 #define TYPE_MAXIMUM(t) \
59 ((t) (! TYPE_SIGNED (t) \
61 : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
64 check_for_SIGALRM (int sig)
73 static struct timespec ts_sleep;
74 static struct timespec ts_remaining;
75 static struct sigaction act;
78 act.sa_handler = check_for_SIGALRM;
79 sigemptyset (&act.sa_mask);
80 sigaction (SIGALRM, &act, NULL);
84 if (nanosleep (&ts_sleep, NULL) != 0)
86 ts_sleep.tv_sec = TYPE_MAXIMUM (time_t);
87 ts_sleep.tv_nsec = 999999999;
89 if (nanosleep (&ts_sleep, &ts_remaining) == -1 && errno == EINTR
90 && TYPE_MAXIMUM (time_t) - 10 < ts_remaining.tv_sec)
94 [gl_cv_func_nanosleep=yes],
96 119) gl_cv_func_nanosleep='no (mishandles large arguments)';; dnl (
97 *) gl_cv_func_nanosleep=no;;
99 [gl_cv_func_nanosleep=cross-compiling])
101 if test "$gl_cv_func_nanosleep" = yes; then
105 if test "$gl_cv_func_nanosleep" = 'no (mishandles large arguments)'; then
106 AC_DEFINE([HAVE_BUG_BIG_NANOSLEEP], [1],
107 [Define to 1 if nanosleep mishandles large arguments.])
109 for ac_lib in $LIBSOCKET; do
110 case " $LIB_NANOSLEEP " in
112 *) LIB_NANOSLEEP="$LIB_NANOSLEEP $ac_lib";;
120 LIBS=$nanosleep_save_libs
121 if test $HAVE_NANOSLEEP = 0 || test $REPLACE_NANOSLEEP = 1; then
122 AC_LIBOBJ([nanosleep])
127 # Prerequisites of lib/nanosleep.c.
128 AC_DEFUN([gl_PREREQ_NANOSLEEP],
130 AC_CHECK_HEADERS_ONCE([sys/select.h])
131 gl_PREREQ_SIG_HANDLER_H