Improve responsiveness while in 'replace-buffer-contents'
[emacs.git] / m4 / pselect.m4
blobedf4d8282095d8a7b0f0ba7630d2392319ff054e
1 # pselect.m4 serial 6
2 dnl Copyright (C) 2011-2018 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 ]],[[
41   fd_set set;
42   dup2(0, 16);
43   FD_ZERO(&set);
44   FD_SET(16, &set);
45   close(16);
46   struct timespec timeout;
47   timeout.tv_sec = 0;
48   timeout.tv_nsec = 5000;
49   return pselect (17, &set, NULL, NULL, &timeout, NULL) != -1 || errno != EBADF;
50 ]])], [gl_cv_func_pselect_detects_ebadf=yes],
51       [gl_cv_func_pselect_detects_ebadf=no],
52           [
53            case "$host_os" in
54                            # Guess yes on glibc systems.
55             *-gnu* | gnu*) gl_cv_func_pselect_detects_ebadf="guessing yes" ;;
56                            # If we don't know, assume the worst.
57             *)             gl_cv_func_pselect_detects_ebadf="guessing no" ;;
58            esac
59           ])
60       ])
61     case $gl_cv_func_pselect_detects_ebadf in
62       *yes) ;;
63       *) REPLACE_PSELECT=1 ;;
64     esac
65   fi
67   if test $ac_cv_func_pselect = no || test $gl_cv_sig_pselect = no; then
68     REPLACE_PSELECT=1
69   fi