test-framework-sh: Fix typo in function invocation (regression 2024-06-11).
[gnulib.git] / m4 / poll.m4
blob787636d46403e53c56c817fd0a5da30adc6656f8
1 # poll.m4
2 # serial 22
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
14     ac_cv_func_poll=no
15     gl_cv_func_poll=no
16   else
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 10.15 and AIX 5.3, it doesn't.
20        AC_RUN_IFELSE([AC_LANG_SOURCE([[
21 #include <fcntl.h>
22 #include <poll.h>
23 ]GL_MDA_DEFINES[
24          int main()
25          {
26            int result = 0;
27            struct pollfd ufd;
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. */
31            if (ufd.fd >= 0)
32              {
33                ufd.events = POLLIN;
34                ufd.revents = 0;
35                if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLIN))
36                  result |= 1;
37              }
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. */
41            if (ufd.fd >= 0)
42              {
43                ufd.events = POLLOUT;
44                ufd.revents = 0;
45                if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLOUT))
46                  result |= 2;
47              }
48            /* Trying /dev/tty may be too environment dependent.  */
49            return result;
50          }]])],
51          [gl_cv_func_poll=yes],
52          [gl_cv_func_poll=no],
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)
57 This is MacOSX or AIX
58 #endif
59 ], [gl_cv_func_poll="guessing no"], [gl_cv_func_poll="guessing yes"])])])
60   fi
61   case "$gl_cv_func_poll" in
62     *yes) ;;
63     *)
64       AC_CHECK_FUNC([poll], [ac_cv_func_poll=yes], [ac_cv_func_poll=no])
65       if test $ac_cv_func_poll = no; then
66         HAVE_POLL=0
67       else
68         REPLACE_POLL=1
69       fi
70       ;;
71   esac
72   if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
73     :
74   else
75     AC_DEFINE([HAVE_POLL], [1],
76       [Define to 1 if you have the 'poll' function and it works.])
77   fi
79   dnl Determine the needed libraries.
80   POLL_LIB="$LIBSOCKET"
81   if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
82     case "$host_os" in
83       mingw* | windows*)
84         dnl On the MSVC platform, the function MsgWaitForMultipleObjects
85         dnl (used in lib/poll.c) requires linking with -luser32. On mingw,
86         dnl it is implicit.
87         AC_LINK_IFELSE(
88           [AC_LANG_SOURCE([[
89 #define WIN32_LEAN_AND_MEAN
90 #include <windows.h>
91 int
92 main ()
94   MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
95   return 0;
96 }]])],
97           [],
98           [POLL_LIB="$POLL_LIB -luser32"])
99         ;;
100     esac
101   fi
102   AC_SUBST([POLL_LIB])
103   dnl For backward compatibility.
104   LIB_POLL="$POLL_LIB"
105   AC_SUBST([LIB_POLL])
108 # Prerequisites of lib/poll.c.
109 AC_DEFUN([gl_PREREQ_POLL],
111   AC_CHECK_HEADERS_ONCE([sys/ioctl.h sys/filio.h])