Blame m4/poll.m4

Packit 8f70b4
# poll.m4 serial 18
Packit 8f70b4
dnl Copyright (c) 2003, 2005-2007, 2009-2018 Free Software Foundation, Inc.
Packit 8f70b4
dnl This file is free software; the Free Software Foundation
Packit 8f70b4
dnl gives unlimited permission to copy and/or distribute it,
Packit 8f70b4
dnl with or without modifications, as long as this notice is preserved.
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_FUNC_POLL],
Packit 8f70b4
[
Packit 8f70b4
  AC_REQUIRE([gl_POLL_H])
Packit 8f70b4
  AC_REQUIRE([gl_SOCKETS])
Packit 8f70b4
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit 8f70b4
  if test $ac_cv_header_poll_h = no; then
Packit 8f70b4
    ac_cv_func_poll=no
Packit 8f70b4
    gl_cv_func_poll=no
Packit 8f70b4
  else
Packit 8f70b4
    AC_CHECK_FUNC([poll],
Packit 8f70b4
      [# Check whether poll() works on special files (like /dev/null) and
Packit 8f70b4
       # and ttys (like /dev/tty). On Mac OS X 10.4.0 and AIX 5.3, it doesn't.
Packit 8f70b4
       AC_RUN_IFELSE([AC_LANG_SOURCE([[
Packit 8f70b4
#include <fcntl.h>
Packit 8f70b4
#include <poll.h>
Packit 8f70b4
         int main()
Packit 8f70b4
         {
Packit 8f70b4
           int result = 0;
Packit 8f70b4
           struct pollfd ufd;
Packit 8f70b4
           /* Try /dev/null for reading.  */
Packit 8f70b4
           ufd.fd = open ("/dev/null", O_RDONLY);
Packit 8f70b4
           /* If /dev/null does not exist, it's not Mac OS X nor AIX. */
Packit 8f70b4
           if (ufd.fd >= 0)
Packit 8f70b4
             {
Packit 8f70b4
               ufd.events = POLLIN;
Packit 8f70b4
               ufd.revents = 0;
Packit 8f70b4
               if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLIN))
Packit 8f70b4
                 result |= 1;
Packit 8f70b4
             }
Packit 8f70b4
           /* Try /dev/null for writing.  */
Packit 8f70b4
           ufd.fd = open ("/dev/null", O_WRONLY);
Packit 8f70b4
           /* If /dev/null does not exist, it's not Mac OS X nor AIX. */
Packit 8f70b4
           if (ufd.fd >= 0)
Packit 8f70b4
             {
Packit 8f70b4
               ufd.events = POLLOUT;
Packit 8f70b4
               ufd.revents = 0;
Packit 8f70b4
               if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLOUT))
Packit 8f70b4
                 result |= 2;
Packit 8f70b4
             }
Packit 8f70b4
           /* Trying /dev/tty may be too environment dependent.  */
Packit 8f70b4
           return result;
Packit 8f70b4
         }]])],
Packit 8f70b4
         [gl_cv_func_poll=yes],
Packit 8f70b4
         [gl_cv_func_poll=no],
Packit 8f70b4
         [# When cross-compiling, assume that poll() works everywhere except on
Packit 8f70b4
          # Mac OS X or AIX, regardless of its version.
Packit 8f70b4
          AC_EGREP_CPP([MacOSX], [
Packit 8f70b4
#if (defined(__APPLE__) && defined(__MACH__)) || defined(_AIX)
Packit 8f70b4
This is MacOSX or AIX
Packit 8f70b4
#endif
Packit 8f70b4
], [gl_cv_func_poll=no], [gl_cv_func_poll=yes])])])
Packit 8f70b4
  fi
Packit 8f70b4
  if test $gl_cv_func_poll != yes; then
Packit 8f70b4
    AC_CHECK_FUNC([poll], [ac_cv_func_poll=yes], [ac_cv_func_poll=no])
Packit 8f70b4
    if test $ac_cv_func_poll = no; then
Packit 8f70b4
      HAVE_POLL=0
Packit 8f70b4
    else
Packit 8f70b4
      REPLACE_POLL=1
Packit 8f70b4
    fi
Packit 8f70b4
  fi
Packit 8f70b4
  if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
Packit 8f70b4
    :
Packit 8f70b4
  else
Packit 8f70b4
    AC_DEFINE([HAVE_POLL], [1],
Packit 8f70b4
      [Define to 1 if you have the 'poll' function and it works.])
Packit 8f70b4
  fi
Packit 8f70b4
Packit 8f70b4
  dnl Determine the needed libraries.
Packit 8f70b4
  LIB_POLL="$LIBSOCKET"
Packit 8f70b4
  if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
Packit 8f70b4
    case "$host_os" in
Packit 8f70b4
      mingw*)
Packit 8f70b4
        dnl On the MSVC platform, the function MsgWaitForMultipleObjects
Packit 8f70b4
        dnl (used in lib/poll.c) requires linking with -luser32. On mingw,
Packit 8f70b4
        dnl it is implicit.
Packit 8f70b4
        AC_LINK_IFELSE(
Packit 8f70b4
          [AC_LANG_SOURCE([[
Packit 8f70b4
#define WIN32_LEAN_AND_MEAN
Packit 8f70b4
#include <windows.h>
Packit 8f70b4
int
Packit 8f70b4
main ()
Packit 8f70b4
{
Packit 8f70b4
  MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
Packit 8f70b4
  return 0;
Packit 8f70b4
}]])],
Packit 8f70b4
          [],
Packit 8f70b4
          [LIB_POLL="$LIB_POLL -luser32"])
Packit 8f70b4
        ;;
Packit 8f70b4
    esac
Packit 8f70b4
  fi
Packit 8f70b4
  AC_SUBST([LIB_POLL])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
# Prerequisites of lib/poll.c.
Packit 8f70b4
AC_DEFUN([gl_PREREQ_POLL],
Packit 8f70b4
[
Packit 8f70b4
  AC_CHECK_HEADERS_ONCE([sys/ioctl.h sys/filio.h])
Packit 8f70b4
])