3 dnl Copyright (c) 2003, 2005-2007, 2009-2024 Free Software Foundation, 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.
8 AC_DEFUN([gl_FUNC_POLL],
10 AC_REQUIRE([gl_POLL_H])
11 AC_REQUIRE([gl_SOCKETS])
12 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
13 if test $ac_cv_header_poll_h = no; then
18 [# Check whether poll() works on special files (like /dev/null) and
19 # and ttys (like /dev/tty). On macOS 10.15 and AIX 5.3, it doesn't.
20 AC_RUN_IFELSE([AC_LANG_SOURCE([[
28 /* Try /dev/null for reading. */
29 ufd.fd = open ("/dev/null", O_RDONLY);
30 /* If /dev/null does not exist, it's not Mac OS X nor AIX. */
35 if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLIN))
38 /* Try /dev/null for writing. */
39 ufd.fd = open ("/dev/null", O_WRONLY);
40 /* If /dev/null does not exist, it's not Mac OS X nor AIX. */
45 if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLOUT))
48 /* Trying /dev/tty may be too environment dependent. */
51 [gl_cv_func_poll=yes],
53 [# When cross-compiling, assume that poll() works everywhere except on
54 # Mac OS X or AIX, regardless of its version.
55 AC_EGREP_CPP([MacOSX], [
56 #if (defined(__APPLE__) && defined(__MACH__)) || defined(_AIX)
59 ], [gl_cv_func_poll="guessing no"], [gl_cv_func_poll="guessing yes"])])])
61 case "$gl_cv_func_poll" in
64 AC_CHECK_FUNC([poll], [ac_cv_func_poll=yes], [ac_cv_func_poll=no])
65 if test $ac_cv_func_poll = no; then
72 if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
75 AC_DEFINE([HAVE_POLL], [1],
76 [Define to 1 if you have the 'poll' function and it works.])
79 dnl Determine the needed libraries.
81 if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
84 dnl On the MSVC platform, the function MsgWaitForMultipleObjects
85 dnl (used in lib/poll.c) requires linking with -luser32. On mingw,
89 #define WIN32_LEAN_AND_MEAN
94 MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
98 [POLL_LIB="$POLL_LIB -luser32"])
103 dnl For backward compatibility.
108 # Prerequisites of lib/poll.c.
109 AC_DEFUN([gl_PREREQ_POLL],
111 AC_CHECK_HEADERS_ONCE([sys/ioctl.h sys/filio.h])