Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
[emacs.git] / m4 / pselect.m4
blob2c620de41370b93f7069c15ae92ead688b61a2d3
1 # pselect.m4 serial 2
2 dnl Copyright (C) 2011-2016 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_CHECK_FUNCS_ONCE([pselect])
13   if test $ac_cv_func_pselect = yes; then
14     AC_CACHE_CHECK([whether signature of pselect conforms to POSIX],
15       gl_cv_sig_pselect,
16       [AC_LINK_IFELSE(
17          [AC_LANG_PROGRAM(
18               [[#include <sys/select.h>
19                 ]],
20               [[int (*p) (int, fd_set *, fd_set *, fd_set *restrict,
21                           struct timespec const *restrict,
22                           sigset_t const *restrict) = pselect;
23                 return !p;]])],
24          [gl_cv_sig_pselect=yes],
25          [gl_cv_sig_pselect=no])])
27     dnl On FreeBSD 8.2, pselect() doesn't always reject bad fds.
28     AC_CACHE_CHECK([whether pselect detects invalid fds],
29       [gl_cv_func_pselect_detects_ebadf],
30       [
31         AC_RUN_IFELSE([AC_LANG_PROGRAM([[
32 #include <sys/types.h>
33 #include <sys/time.h>
34 #if HAVE_SYS_SELECT_H
35 # include <sys/select.h>
36 #endif
37 #include <unistd.h>
38 #include <errno.h>
39 ]],[[
40   fd_set set;
41   dup2(0, 16);
42   FD_ZERO(&set);
43   FD_SET(16, &set);
44   close(16);
45   struct timespec timeout;
46   timeout.tv_sec = 0;
47   timeout.tv_nsec = 5000;
48   return pselect (17, &set, NULL, NULL, &timeout, NULL) != -1 || errno != EBADF;
49 ]])], [gl_cv_func_pselect_detects_ebadf=yes],
50       [gl_cv_func_pselect_detects_ebadf=no],
51           [
52            case "$host_os" in
53                     # Guess yes on glibc systems.
54             *-gnu*) gl_cv_func_pselect_detects_ebadf="guessing yes" ;;
55                     # If we don't know, assume the worst.
56             *)      gl_cv_func_pselect_detects_ebadf="guessing no" ;;
57            esac
58           ])
59       ])
60     case $gl_cv_func_pselect_detects_ebadf in
61       *yes) ;;
62       *) REPLACE_PSELECT=1 ;;
63     esac
64   fi
66   if test $ac_cv_func_pselect = no || test $gl_cv_sig_pselect = no; then
67     REPLACE_PSELECT=1
68   fi