Blame m4/sleep.m4

Packit Service 4684c1
# sleep.m4 serial 11
Packit Service 4684c1
dnl Copyright (C) 2007-2020 Free Software Foundation, Inc.
Packit Service 4684c1
dnl This file is free software; the Free Software Foundation
Packit Service 4684c1
dnl gives unlimited permission to copy and/or distribute it,
Packit Service 4684c1
dnl with or without modifications, as long as this notice is preserved.
Packit Service 4684c1
Packit Service 4684c1
AC_DEFUN([gl_FUNC_SLEEP],
Packit Service 4684c1
[
Packit Service 4684c1
  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
Packit Service 4684c1
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service 4684c1
  dnl We expect to see the declaration of sleep() in a header file.
Packit Service 4684c1
  dnl Older versions of mingw have a sleep() function that is an alias to
Packit Service 4684c1
  dnl _sleep() in MSVCRT. It has a different signature than POSIX sleep():
Packit Service 4684c1
  dnl it takes the number of milliseconds as argument and returns void.
Packit Service 4684c1
  dnl mingw does not declare this function.
Packit Service 4684c1
  AC_CHECK_DECLS([sleep], , , [[#include <unistd.h>]])
Packit Service 4684c1
  AC_CHECK_FUNCS_ONCE([sleep])
Packit Service 4684c1
  if test $ac_cv_have_decl_sleep != yes; then
Packit Service 4684c1
    HAVE_SLEEP=0
Packit Service 4684c1
  else
Packit Service 4684c1
    dnl Cygwin 1.5.x has a bug where sleep can't exceed 49.7 days.
Packit Service 4684c1
    AC_CACHE_CHECK([for working sleep], [gl_cv_func_sleep_works],
Packit Service 4684c1
      [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
Packit Service 4684c1
#include <errno.h>
Packit Service 4684c1
#include <unistd.h>
Packit Service 4684c1
#include <signal.h>
Packit Service 4684c1
static void
Packit Service 4684c1
handle_alarm (int sig)
Packit Service 4684c1
{
Packit Service 4684c1
  if (sig != SIGALRM)
Packit Service 4684c1
    _exit (2);
Packit Service 4684c1
}
Packit Service 4684c1
]], [[
Packit Service 4684c1
    /* Failure to compile this test due to missing alarm is okay,
Packit Service 4684c1
       since all such platforms (mingw) also lack sleep.  */
Packit Service 4684c1
    unsigned int pentecost = 50 * 24 * 60 * 60; /* 50 days.  */
Packit Service 4684c1
    unsigned int remaining;
Packit Service 4684c1
    signal (SIGALRM, handle_alarm);
Packit Service 4684c1
    alarm (1);
Packit Service 4684c1
    remaining = sleep (pentecost);
Packit Service 4684c1
    if (remaining > pentecost)
Packit Service 4684c1
      return 3;
Packit Service 4684c1
    if (remaining <= pentecost - 10)
Packit Service 4684c1
      return 4;
Packit Service 4684c1
    return 0;
Packit Service 4684c1
    ]])],
Packit Service 4684c1
      [gl_cv_func_sleep_works=yes], [gl_cv_func_sleep_works=no],
Packit Service 4684c1
      [case "$host_os" in
Packit Service 4684c1
                        # Guess yes on glibc systems.
Packit Service 4684c1
         *-gnu* | gnu*) gl_cv_func_sleep_works="guessing yes" ;;
Packit Service 4684c1
                        # Guess yes on musl systems.
Packit Service 4684c1
         *-musl*)       gl_cv_func_sleep_works="guessing yes" ;;
Packit Service 4684c1
                        # Guess no on native Windows.
Packit Service 4684c1
         mingw*)        gl_cv_func_sleep_works="guessing no" ;;
Packit Service 4684c1
                        # If we don't know, obey --enable-cross-guesses.
Packit Service 4684c1
         *)             gl_cv_func_sleep_works="$gl_cross_guess_normal" ;;
Packit Service 4684c1
       esac
Packit Service 4684c1
      ])])
Packit Service 4684c1
    case "$gl_cv_func_sleep_works" in
Packit Service 4684c1
      *yes) ;;
Packit Service 4684c1
      *)
Packit Service 4684c1
        REPLACE_SLEEP=1
Packit Service 4684c1
        ;;
Packit Service 4684c1
    esac
Packit Service 4684c1
  fi
Packit Service 4684c1
])