New module 'poll-h'.
[gnulib.git] / m4 / poll.m4
1 # poll.m4 serial 10
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_REQUIRE([gl_POLL_H])
11   if test "$ac_cv_header_poll_h" = no; then
12     ac_cv_func_poll=no
13     gl_cv_func_poll=no
14   else
15     AC_CHECK_FUNC([poll],
16       [# Check whether poll() works on special files (like /dev/null) and
17        # and ttys (like /dev/tty). On MacOS X 10.4.0 and AIX 5.3, it doesn't.
18        AC_RUN_IFELSE([AC_LANG_SOURCE([[
19 #include <fcntl.h>
20 #include <poll.h>
21          int main()
22          {
23            struct pollfd ufd;
24            /* Try /dev/null for reading.  */
25            ufd.fd = open ("/dev/null", O_RDONLY);
26            if (ufd.fd < 0)
27              /* If /dev/null does not exist, it's not MacOS X nor AIX. */
28              return 0;
29            ufd.events = POLLIN;
30            ufd.revents = 0;
31            if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLIN))
32              return 1;
33            /* Try /dev/null for writing.  */
34            ufd.fd = open ("/dev/null", O_WRONLY);
35            if (ufd.fd < 0)
36              /* If /dev/null does not exist, it's not MacOS X nor AIX. */
37              return 0;
38            ufd.events = POLLOUT;
39            ufd.revents = 0;
40            if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLOUT))
41              return 1;
42            /* Trying /dev/tty may be too environment dependent.  */
43            return 0;
44          }]])],
45          [gl_cv_func_poll=yes],
46          [gl_cv_func_poll=no],
47          [# When cross-compiling, assume that poll() works everywhere except on
48           # MacOS X or AIX, regardless of its version.
49           AC_EGREP_CPP([MacOSX], [
50 #if (defined(__APPLE__) && defined(__MACH__)) || defined(_AIX)
51 This is MacOSX or AIX
52 #endif
53 ], [gl_cv_func_poll=no], [gl_cv_func_poll=yes])])])
54   fi
55   if test $gl_cv_func_poll != yes; then
56     AC_CHECK_FUNC([poll], [ac_cv_func_poll=yes], [ac_cv_func_poll=no])
57     if test $ac_cv_func_poll = no; then
58       HAVE_POLL=0
59     else
60       REPLACE_POLL=1
61     fi
62   fi
63   if test $HAVE_POLL = 0 || $REPLACE_POLL = 1; then
64     gl_REPLACE_POLL_H
65     AC_LIBOBJ([poll])
66     gl_PREREQ_POLL
67   else
68     AC_DEFINE([HAVE_POLL], [1],
69       [Define to 1 if you have the 'poll' function and it works.])
70   fi
71 ])
72
73 # Prerequisites of lib/poll.c.
74 AC_DEFUN([gl_PREREQ_POLL],
75 [
76   AC_CHECK_HEADERS_ONCE([sys/ioctl.h sys/filio.h])
77 ])