poll.m4 3.3 KB

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