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