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