| 1 |
# poll.m4 |
| 2 |
# serial 22 |
| 3 |
dnl Copyright (c) 2003, 2005-2007, 2009-2026 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. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_POLL], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_POLL_H]) |
| 12 |
AC_REQUIRE([gl_SOCKETS]) |
| 13 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 14 |
if test $ac_cv_header_poll_h = no; then |
| 15 |
ac_cv_func_poll=no |
| 16 |
gl_cv_func_poll=no |
| 17 |
else |
| 18 |
AC_CHECK_FUNC([poll], |
| 19 |
[# Check whether poll() works on special files (like /dev/null) and |
| 20 |
# and ttys (like /dev/tty). On macOS 10.15 and AIX 5.3, it doesn't. |
| 21 |
AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
| 22 |
#include <fcntl.h> |
| 23 |
#include <poll.h> |
| 24 |
]GL_MDA_DEFINES[ |
| 25 |
int main() |
| 26 |
{ |
| 27 |
int result = 0; |
| 28 |
struct pollfd ufd; |
| 29 |
/* Try /dev/null for reading. */ |
| 30 |
ufd.fd = open ("/dev/null", O_RDONLY); |
| 31 |
/* If /dev/null does not exist, it's not Mac OS X nor AIX. */ |
| 32 |
if (ufd.fd >= 0) |
| 33 |
{ |
| 34 |
ufd.events = POLLIN; |
| 35 |
ufd.revents = 0; |
| 36 |
if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLIN)) |
| 37 |
result |= 1; |
| 38 |
} |
| 39 |
/* Try /dev/null for writing. */ |
| 40 |
ufd.fd = open ("/dev/null", O_WRONLY); |
| 41 |
/* If /dev/null does not exist, it's not Mac OS X nor AIX. */ |
| 42 |
if (ufd.fd >= 0) |
| 43 |
{ |
| 44 |
ufd.events = POLLOUT; |
| 45 |
ufd.revents = 0; |
| 46 |
if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLOUT)) |
| 47 |
result |= 2; |
| 48 |
} |
| 49 |
/* Trying /dev/tty may be too environment dependent. */ |
| 50 |
return result; |
| 51 |
}]])], |
| 52 |
[gl_cv_func_poll=yes], |
| 53 |
[gl_cv_func_poll=no], |
| 54 |
[# When cross-compiling, assume that poll() works everywhere except on |
| 55 |
# Mac OS X or AIX, regardless of its version. |
| 56 |
AC_EGREP_CPP([MacOSX], [ |
| 57 |
#if (defined(__APPLE__) && defined(__MACH__)) || defined(_AIX) |
| 58 |
This is MacOSX or AIX |
| 59 |
#endif |
| 60 |
], [gl_cv_func_poll="guessing no"], [gl_cv_func_poll="guessing yes"])])]) |
| 61 |
fi |
| 62 |
case "$gl_cv_func_poll" in |
| 63 |
*yes) ;; |
| 64 |
*) |
| 65 |
AC_CHECK_FUNC([poll], [ac_cv_func_poll=yes], [ac_cv_func_poll=no]) |
| 66 |
if test $ac_cv_func_poll = no; then |
| 67 |
HAVE_POLL=0 |
| 68 |
else |
| 69 |
REPLACE_POLL=1 |
| 70 |
fi |
| 71 |
;; |
| 72 |
esac |
| 73 |
if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then |
| 74 |
: |
| 75 |
else |
| 76 |
AC_DEFINE([HAVE_POLL], [1], |
| 77 |
[Define to 1 if you have the 'poll' function and it works.]) |
| 78 |
fi |
| 79 |
|
| 80 |
dnl Determine the needed libraries. |
| 81 |
POLL_LIB="$LIBSOCKET" |
| 82 |
if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then |
| 83 |
case "$host_os" in |
| 84 |
mingw* | windows*) |
| 85 |
dnl On the MSVC platform, the function MsgWaitForMultipleObjects |
| 86 |
dnl (used in lib/poll.c) requires linking with -luser32. On mingw, |
| 87 |
dnl it is implicit. |
| 88 |
AC_LINK_IFELSE( |
| 89 |
[AC_LANG_SOURCE([[ |
| 90 |
#define WIN32_LEAN_AND_MEAN |
| 91 |
#include <windows.h> |
| 92 |
int |
| 93 |
main () |
| 94 |
{ |
| 95 |
MsgWaitForMultipleObjects (0, NULL, 0, 0, 0); |
| 96 |
return 0; |
| 97 |
}]])], |
| 98 |
[], |
| 99 |
[POLL_LIB="$POLL_LIB -luser32"]) |
| 100 |
;; |
| 101 |
esac |
| 102 |
fi |
| 103 |
AC_SUBST([POLL_LIB]) |
| 104 |
dnl For backward compatibility. |
| 105 |
LIB_POLL="$POLL_LIB" |
| 106 |
AC_SUBST([LIB_POLL]) |
| 107 |
]) |
| 108 |
|
| 109 |
# Prerequisites of lib/poll.c. |
| 110 |
AC_DEFUN([gl_PREREQ_POLL], |
| 111 |
[ |
| 112 |
AC_CHECK_HEADERS_ONCE([sys/ioctl.h sys/filio.h]) |
| 113 |
]) |