| 1 |
# sleep.m4 |
| 2 |
# serial 14 |
| 3 |
dnl Copyright (C) 2007-2026 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. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_SLEEP], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 13 |
dnl We expect to see the declaration of sleep() in a header file. |
| 14 |
dnl Older versions of mingw have a sleep() function that is an alias to |
| 15 |
dnl _sleep() in MSVCRT. It has a different signature than POSIX sleep(): |
| 16 |
dnl it takes the number of milliseconds as argument and returns void. |
| 17 |
dnl mingw does not declare this function. |
| 18 |
AC_CHECK_DECLS([sleep], , , [[#include <unistd.h>]]) |
| 19 |
AC_CHECK_FUNCS_ONCE([sleep]) |
| 20 |
if test $ac_cv_have_decl_sleep != yes; then |
| 21 |
HAVE_SLEEP=0 |
| 22 |
else |
| 23 |
dnl Cygwin 1.5.x has a bug where sleep can't exceed 49.7 days. |
| 24 |
AC_CACHE_CHECK([for working sleep], [gl_cv_func_sleep_works], |
| 25 |
[AC_RUN_IFELSE([AC_LANG_PROGRAM([[ |
| 26 |
#include <errno.h> |
| 27 |
#include <unistd.h> |
| 28 |
#include <signal.h> |
| 29 |
static void |
| 30 |
handle_alarm (int sig) |
| 31 |
{ |
| 32 |
if (sig != SIGALRM) |
| 33 |
_exit (2); |
| 34 |
} |
| 35 |
]], [[ |
| 36 |
/* Failure to compile this test due to missing alarm is okay, |
| 37 |
since all such platforms (mingw, MSVC) also lack sleep. */ |
| 38 |
unsigned int pentecost = 50 * 24 * 60 * 60; /* 50 days. */ |
| 39 |
unsigned int remaining; |
| 40 |
signal (SIGALRM, handle_alarm); |
| 41 |
alarm (1); |
| 42 |
remaining = sleep (pentecost); |
| 43 |
if (remaining > pentecost) |
| 44 |
return 3; |
| 45 |
if (remaining <= pentecost - 10) |
| 46 |
return 4; |
| 47 |
return 0; |
| 48 |
]])], |
| 49 |
[gl_cv_func_sleep_works=yes], [gl_cv_func_sleep_works=no], |
| 50 |
[case "$host_os" in |
| 51 |
# Guess yes on glibc systems. |
| 52 |
*-gnu* | gnu*) gl_cv_func_sleep_works="guessing yes" ;; |
| 53 |
# Guess yes on musl systems. |
| 54 |
*-musl*) gl_cv_func_sleep_works="guessing yes" ;; |
| 55 |
# Guess yes on systems that emulate the Linux system calls. |
| 56 |
midipix*) gl_cv_func_sleep_works="guessing yes" ;; |
| 57 |
# Guess no on native Windows. |
| 58 |
mingw* | windows*) gl_cv_func_sleep_works="guessing no" ;; |
| 59 |
# If we don't know, obey --enable-cross-guesses. |
| 60 |
*) gl_cv_func_sleep_works="$gl_cross_guess_normal" ;; |
| 61 |
esac |
| 62 |
])]) |
| 63 |
case "$gl_cv_func_sleep_works" in |
| 64 |
*yes) ;; |
| 65 |
*) |
| 66 |
REPLACE_SLEEP=1 |
| 67 |
;; |
| 68 |
esac |
| 69 |
fi |
| 70 |
]) |