Debian Codegraph @

m4/select.m4

raw
1 # select.m4
2 # serial 16
3 dnl Copyright (C) 2009-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.
8
9 AC_DEFUN([gl_FUNC_SELECT],
10 [
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_REQUIRE([gl_SOCKETS])
15 if test "$ac_cv_header_winsock2_h" = yes; then
16 REPLACE_SELECT=1
17 else
18 dnl On Interix 3.5, select(0, NULL, NULL, NULL, timeout) fails with error
19 dnl EFAULT.
20 AC_CHECK_HEADERS_ONCE([sys/select.h])
21 AC_CACHE_CHECK([whether select supports a 0 argument],
22 [gl_cv_func_select_supports0],
23 [
24 AC_RUN_IFELSE([AC_LANG_SOURCE([[
25 #include <sys/types.h>
26 #include <sys/time.h>
27 #if HAVE_SYS_SELECT_H
28 #include <sys/select.h>
29 #endif
30 int main ()
31 {
32 struct timeval timeout;
33 timeout.tv_sec = 0;
34 timeout.tv_usec = 5;
35 return select (0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout) < 0;
36 }]])], [gl_cv_func_select_supports0=yes], [gl_cv_func_select_supports0=no],
37 [
38 changequote(,)dnl
39 case "$host_os" in
40 # Guess no on Interix.
41 interix*) gl_cv_func_select_supports0="guessing no";;
42 # Guess yes otherwise.
43 *) gl_cv_func_select_supports0="guessing yes";;
44 esac
45 changequote([,])dnl
46 ])
47 ])
48 case "$gl_cv_func_select_supports0" in
49 *yes) ;;
50 *) REPLACE_SELECT=1 ;;
51 esac
52
53 dnl On FreeBSD 8.2, select() doesn't always reject bad fds.
54 AC_CACHE_CHECK([whether select detects invalid fds],
55 [gl_cv_func_select_detects_ebadf],
56 [
57 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
58 #include <sys/types.h>
59 #include <sys/time.h>
60 #if HAVE_SYS_SELECT_H
61 # include <sys/select.h>
62 #endif
63 #include <unistd.h>
64 #include <errno.h>
65 ]GL_MDA_DEFINES],
66 [[
67 fd_set set;
68 dup2(0, 16);
69 FD_ZERO(&set);
70 FD_SET(16, &set);
71 close(16);
72 struct timeval timeout;
73 timeout.tv_sec = 0;
74 timeout.tv_usec = 5;
75 return select (17, &set, NULL, NULL, &timeout) != -1 || errno != EBADF;
76 ]])], [gl_cv_func_select_detects_ebadf=yes],
77 [gl_cv_func_select_detects_ebadf=no],
78 [
79 case "$host_os" in
80 # Guess yes on Linux systems.
81 linux-* | linux) gl_cv_func_select_detects_ebadf="guessing yes" ;;
82 # Guess yes on systems that emulate the Linux system calls.
83 midipix*) gl_cv_func_select_detects_ebadf="guessing yes" ;;
84 # Guess yes on glibc systems.
85 *-gnu* | gnu*) gl_cv_func_select_detects_ebadf="guessing yes" ;;
86 # If we don't know, obey --enable-cross-guesses.
87 *) gl_cv_func_select_detects_ebadf="$gl_cross_guess_normal" ;;
88 esac
89 ])
90 ])
91 case $gl_cv_func_select_detects_ebadf in
92 *yes) ;;
93 *) REPLACE_SELECT=1 ;;
94 esac
95 fi
96
97 dnl Determine the needed libraries.
98 SELECT_LIB="$LIBSOCKET"
99 if test $REPLACE_SELECT = 1; then
100 case "$host_os" in
101 mingw* | windows*)
102 dnl On the MSVC platform, the function MsgWaitForMultipleObjects
103 dnl (used in lib/select.c) requires linking with -luser32. On mingw,
104 dnl it is implicit.
105 AC_LINK_IFELSE(
106 [AC_LANG_SOURCE([[
107 #define WIN32_LEAN_AND_MEAN
108 #include <windows.h>
109 int
110 main ()
111 {
112 MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
113 return 0;
114 }]])],
115 [],
116 [SELECT_LIB="$SELECT_LIB -luser32"])
117 ;;
118 esac
119 fi
120 AC_SUBST([SELECT_LIB])
121 dnl For backward compatibility.
122 LIB_SELECT="$LIB_SELECT"
123 AC_SUBST([LIB_SELECT])
124 ])