immutable: Add tests.
[gnulib.git] / m4 / usleep.m4
blob132a83b5596aec26e7f3ae084b4dcc6780335680
1 # usleep.m4 serial 7
2 dnl Copyright (C) 2009-2021 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 dnl This macro intentionally does not check for select or nanosleep;
8 dnl both of those modules can require external libraries.
9 AC_DEFUN([gl_FUNC_USLEEP],
11   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
12   dnl usleep was required in POSIX 2001, but dropped as obsolete in
13   dnl POSIX 2008; therefore, it is not always exposed in headers.
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
16   AC_CHECK_FUNCS_ONCE([usleep])
17   AC_CHECK_TYPE([useconds_t], [],
18     [AC_DEFINE([useconds_t], [unsigned int], [Define to an unsigned 32-bit
19       type if <sys/types.h> lacks this type.])])
20   if test $ac_cv_func_usleep = no; then
21     HAVE_USLEEP=0
22   else
23     dnl POSIX allows implementations to reject arguments larger than
24     dnl 999999, but GNU guarantees it will work.
25     AC_CACHE_CHECK([whether usleep allows large arguments],
26       [gl_cv_func_usleep_works],
27       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
28 #include <unistd.h>
29 ]], [[return !!usleep (1000000);]])],
30         [gl_cv_func_usleep_works=yes], [gl_cv_func_usleep_works=no],
31         [case "$host_os" in
32                           # Guess yes on glibc systems.
33            *-gnu* | gnu*) gl_cv_func_usleep_works="guessing yes" ;;
34                           # Guess yes on musl systems.
35            *-musl*)       gl_cv_func_usleep_works="guessing yes" ;;
36                           # Guess no on native Windows.
37            mingw*)        gl_cv_func_usleep_works="guessing no" ;;
38                           # If we don't know, obey --enable-cross-guesses.
39            *)             gl_cv_func_usleep_works="$gl_cross_guess_normal" ;;
40          esac
41         ])])
42     case "$gl_cv_func_usleep_works" in
43       *yes) ;;
44       *)
45         REPLACE_USLEEP=1
46         ;;
47     esac
48   fi