Unify tests that set gl_cv_func_ldexp_no_libm.
[gnulib.git] / m4 / poll.m4
1 # poll.m4 serial 9
2 dnl Copyright (c) 2003, 2005, 2006, 2007, 2009, 2010 Free Software Foundation,
3 dnl Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7
8 AC_DEFUN([gl_FUNC_POLL],
9 [
10   AC_CHECK_HEADERS([poll.h])
11   if test "$ac_cv_header_poll_h" = no; then
12     gl_cv_func_poll=no
13   else
14     AC_CHECK_FUNC([poll],
15       [# Check whether poll() works on special files (like /dev/null) and
16        # and ttys (like /dev/tty). On MacOS X 10.4.0 and AIX 5.3, it doesn't.
17        AC_RUN_IFELSE([AC_LANG_SOURCE([[
18 #include <fcntl.h>
19 #include <poll.h>
20          int main()
21          {
22            struct pollfd ufd;
23            /* Try /dev/null for reading.  */
24            ufd.fd = open ("/dev/null", O_RDONLY);
25            if (ufd.fd < 0)
26              /* If /dev/null does not exist, it's not MacOS X nor AIX. */
27              return 0;
28            ufd.events = POLLIN;
29            ufd.revents = 0;
30            if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLIN))
31              return 1;
32            /* Try /dev/null for writing.  */
33            ufd.fd = open ("/dev/null", O_WRONLY);
34            if (ufd.fd < 0)
35              /* If /dev/null does not exist, it's not MacOS X nor AIX. */
36              return 0;
37            ufd.events = POLLOUT;
38            ufd.revents = 0;
39            if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLOUT))
40              return 1;
41            /* Trying /dev/tty may be too environment dependent.  */
42            return 0;
43          }]])],
44          [gl_cv_func_poll=yes],
45          [gl_cv_func_poll=no],
46          [# When cross-compiling, assume that poll() works everywhere except on
47           # MacOS X or AIX, regardless of its version.
48           AC_EGREP_CPP([MacOSX], [
49 #if (defined(__APPLE__) && defined(__MACH__)) || defined(_AIX)
50 This is MacOSX or AIX
51 #endif
52 ], [gl_cv_func_poll=no], [gl_cv_func_poll=yes])])])
53   fi
54   if test $gl_cv_func_poll = yes; then
55     AC_DEFINE([HAVE_POLL], [1],
56       [Define to 1 if you have the 'poll' function and it works.])
57     POLL_H=
58   else
59     AC_LIBOBJ([poll])
60     AC_DEFINE([poll], [rpl_poll],
61       [Define to poll if the replacement function should be used.])
62     gl_PREREQ_POLL
63     POLL_H=poll.h
64   fi
65   AC_SUBST([POLL_H])
66 ])
67
68 # Prerequisites of lib/poll.c.
69 AC_DEFUN([gl_PREREQ_POLL],
70 [
71   AC_CHECK_HEADERS_ONCE([sys/ioctl.h sys/filio.h])
72 ])