Don't use poll() on MacOS X 10.4.
[gnulib.git] / m4 / poll.m4
1 # poll.m4 serial 4
2 dnl Copyright (c) 2003, 2005 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     POLL_H=poll.h
12   else
13     POLL_H=
14   fi
15   AC_SUBST([POLL_H])
16
17   AC_CHECK_FUNC(poll,
18     [# Check whether poll() works on special files (like /dev/null) and
19      # and ttys (like /dev/tty). On MacOS X 10.4.0, it doesn't.
20      AC_TRY_RUN([
21 #include <fcntl.h>
22 #include <poll.h>
23        int main()
24        {
25          struct pollfd ufd;
26          /* Try /dev/null for reading.  */
27          ufd.fd = open ("/dev/null", O_RDONLY);
28          if (ufd.fd < 0) /* If /dev/null does not exist, it's not MacOS X. */
29            return 0;
30          ufd.events = POLLIN;
31          ufd.revents = 0;
32          if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLIN))
33            return 1;
34          /* Try /dev/null for writing.  */
35          ufd.fd = open ("/dev/null", O_WRONLY);
36          if (ufd.fd < 0) /* If /dev/null does not exist, it's not MacOS X. */
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, regardless of its version.
49         AC_EGREP_CPP([MacOSX], [
50 #if defined(__APPLE__) && defined(__MACH__)
51 This is MacOSX
52 #endif
53 ], [gl_cv_func_poll=no], [gl_cv_func_poll=yes])])])
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   fi
58
59   if test $gl_cv_func_poll = no; then
60     AC_LIBOBJ(poll)
61     AC_DEFINE(poll, rpl_poll,
62       [Define to poll if the replacement function should be used.])
63     gl_PREREQ_POLL
64   fi
65 ])
66
67 # Prerequisites of lib/poll.c.
68 AC_DEFUN([gl_PREREQ_POLL],
69 [
70   AC_REQUIRE([AC_HEADER_TIME])
71   AC_CHECK_HEADERS_ONCE(sys/time.h)
72 ])