2 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_SLEEP],
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
11 dnl We expect to see the declaration of sleep() in a header file.
12 dnl Older versions of mingw have a sleep() function that is an alias to
13 dnl _sleep() in MSVCRT. It has a different signature than POSIX sleep():
14 dnl it takes the number of milliseconds as argument and returns void.
15 dnl mingw does not declare this function.
16 AC_CHECK_DECLS([sleep], , , [[#include <unistd.h>]])
17 AC_CHECK_FUNCS_ONCE([sleep])
18 if test $ac_cv_have_decl_sleep != yes; then
21 dnl Cygwin 1.5.x has a bug where sleep can't exceed 49.7 days.
22 AC_CACHE_CHECK([for working sleep], [gl_cv_func_sleep_works],
23 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
28 handle_alarm (int sig)
34 /* Failure to compile this test due to missing alarm is okay,
35 since all such platforms (mingw) also lack sleep. */
36 unsigned int pentecost = 50 * 24 * 60 * 60; /* 50 days. */
37 unsigned int remaining;
38 signal (SIGALRM, handle_alarm);
40 remaining = sleep (pentecost);
41 if (remaining > pentecost)
43 if (remaining <= pentecost - 10)
47 [gl_cv_func_sleep_works=yes], [gl_cv_func_sleep_works=no],
49 # Guess yes on glibc systems.
50 *-gnu* | gnu*) gl_cv_func_sleep_works="guessing yes" ;;
51 # Guess yes on musl systems.
52 *-musl*) gl_cv_func_sleep_works="guessing yes" ;;
53 # Guess no on native Windows.
54 mingw*) gl_cv_func_sleep_works="guessing no" ;;
55 # If we don't know, obey --enable-cross-guesses.
56 *) gl_cv_func_sleep_works="$gl_cross_guess_normal" ;;
59 case "$gl_cv_func_sleep_works" in