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