07fa9e9d433abb603376eedfadc8283c1f7b1de9
[gnulib.git] / m4 / usleep.m4
1 # usleep.m4 serial 2
2 dnl Copyright (C) 2009-2012 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.
6
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],
10 [
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_CHECK_FUNCS_ONCE([usleep])
16   AC_CHECK_TYPE([useconds_t], [],
17     [AC_DEFINE([useconds_t], [unsigned int], [Define to an unsigned 32-bit
18       type if <sys/types.h> lacks this type.])])
19   if test $ac_cv_func_usleep = no; then
20     HAVE_USLEEP=0
21   else
22     dnl POSIX allows implementations to reject arguments larger than
23     dnl 999999, but GNU guarantees it will work.
24     AC_CACHE_CHECK([whether usleep allows large arguments],
25       [gl_cv_func_usleep_works],
26       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
27 #include <unistd.h>
28 ]], [[return !!usleep (1000000);]])],
29         [gl_cv_func_usleep_works=yes], [gl_cv_func_usleep_works=no],
30         [gl_cv_func_usleep_works="guessing no"])])
31     if test "$gl_cv_func_usleep_works" != yes; then
32       REPLACE_USLEEP=1
33     fi
34   fi
35 ])