Blame m4/sleep.m4

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