Do the Windows oldnames workaround through the C++ GNULIB_NAMESPACE.
[gnulib.git] / m4 / pselect.m4
blob08a5823c6f90c4224883a7f4ade52e5a77d9f41e
1 # pselect.m4 serial 9
2 dnl Copyright (C) 2011-2020 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.
7 AC_DEFUN([gl_FUNC_PSELECT],
9   AC_REQUIRE([gl_HEADER_SYS_SELECT])
10   AC_REQUIRE([AC_C_RESTRICT])
11   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12   AC_CHECK_FUNCS_ONCE([pselect])
14   if test $ac_cv_func_pselect = yes; then
15     AC_CACHE_CHECK([whether signature of pselect conforms to POSIX],
16       [gl_cv_sig_pselect],
17       [AC_LINK_IFELSE(
18          [AC_LANG_PROGRAM(
19               [[#include <sys/select.h>
20                 ]],
21               [[int (*p) (int, fd_set *, fd_set *, fd_set *restrict,
22                           struct timespec const *restrict,
23                           sigset_t const *restrict) = pselect;
24                 return !p;]])],
25          [gl_cv_sig_pselect=yes],
26          [gl_cv_sig_pselect=no])])
28     dnl On FreeBSD 8.2, pselect() doesn't always reject bad fds.
29     AC_CACHE_CHECK([whether pselect detects invalid fds],
30       [gl_cv_func_pselect_detects_ebadf],
31       [
32         AC_RUN_IFELSE([AC_LANG_PROGRAM([[
33 #include <sys/types.h>
34 #include <sys/time.h>
35 #if HAVE_SYS_SELECT_H
36 # include <sys/select.h>
37 #endif
38 #include <unistd.h>
39 #include <errno.h>
40 ]GL_MDA_DEFINES],
42   fd_set set;
43   dup2(0, 16);
44   FD_ZERO(&set);
45   FD_SET(16, &set);
46   close(16);
47   struct timespec timeout;
48   timeout.tv_sec = 0;
49   timeout.tv_nsec = 5000;
50   return pselect (17, &set, NULL, NULL, &timeout, NULL) != -1 || errno != EBADF;
51 ]])], [gl_cv_func_pselect_detects_ebadf=yes],
52       [gl_cv_func_pselect_detects_ebadf=no],
53           [
54            case "$host_os" in
55                              # Guess yes on Linux systems.
56             linux-* | linux) gl_cv_func_pselect_detects_ebadf="guessing yes" ;;
57                              # Guess yes on glibc systems.
58             *-gnu* | gnu*)   gl_cv_func_pselect_detects_ebadf="guessing yes" ;;
59                              # If we don't know, obey --enable-cross-guesses.
60             *)               gl_cv_func_pselect_detects_ebadf="$gl_cross_guess_normal" ;;
61            esac
62           ])
63       ])
64     case $gl_cv_func_pselect_detects_ebadf in
65       *yes) ;;
66       *) REPLACE_PSELECT=1 ;;
67     esac
68   fi
70   if test $ac_cv_func_pselect = no || test $gl_cv_sig_pselect = no; then
71     REPLACE_PSELECT=1
72   fi