2 dnl Copyright (c) 2003, 2005-2007, 2009-2020 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.
7 AC_DEFUN([gl_FUNC_POLL],
9 AC_REQUIRE([gl_POLL_H])
10 AC_REQUIRE([gl_SOCKETS])
11 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12 if test $ac_cv_header_poll_h = no; then
17 [# Check whether poll() works on special files (like /dev/null) and
18 # and ttys (like /dev/tty). On Mac OS X 10.4.0 and AIX 5.3, it doesn't.
19 AC_RUN_IFELSE([AC_LANG_SOURCE([[
26 /* Try /dev/null for reading. */
27 ufd.fd = open ("/dev/null", O_RDONLY);
28 /* If /dev/null does not exist, it's not Mac OS X nor AIX. */
33 if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLIN))
36 /* Try /dev/null for writing. */
37 ufd.fd = open ("/dev/null", O_WRONLY);
38 /* If /dev/null does not exist, it's not Mac OS X nor AIX. */
43 if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLOUT))
46 /* Trying /dev/tty may be too environment dependent. */
49 [gl_cv_func_poll=yes],
51 [# When cross-compiling, assume that poll() works everywhere except on
52 # Mac OS X or AIX, regardless of its version.
53 AC_EGREP_CPP([MacOSX], [
54 #if (defined(__APPLE__) && defined(__MACH__)) || defined(_AIX)
57 ], [gl_cv_func_poll="guessing no"], [gl_cv_func_poll="guessing yes"])])])
59 case "$gl_cv_func_poll" in
62 AC_CHECK_FUNC([poll], [ac_cv_func_poll=yes], [ac_cv_func_poll=no])
63 if test $ac_cv_func_poll = no; then
70 if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
73 AC_DEFINE([HAVE_POLL], [1],
74 [Define to 1 if you have the 'poll' function and it works.])
77 dnl Determine the needed libraries.
79 if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
82 dnl On the MSVC platform, the function MsgWaitForMultipleObjects
83 dnl (used in lib/poll.c) requires linking with -luser32. On mingw,
87 #define WIN32_LEAN_AND_MEAN
92 MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
96 [LIB_POLL="$LIB_POLL -luser32"])
103 # Prerequisites of lib/poll.c.
104 AC_DEFUN([gl_PREREQ_POLL],
106 AC_CHECK_HEADERS_ONCE([sys/ioctl.h sys/filio.h])