poll.m4 3.1 KB

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