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