2 dnl Copyright (C) 2009-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_SELECT],
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_REQUIRE([gl_SOCKETS])
13 if test "$ac_cv_header_winsock2_h" = yes; then
16 dnl On Interix 3.5, select(0, NULL, NULL, NULL, timeout) fails with error
18 AC_CHECK_HEADERS_ONCE([sys/select.h])
19 AC_CACHE_CHECK([whether select supports a 0 argument],
20 [gl_cv_func_select_supports0],
22 AC_RUN_IFELSE([AC_LANG_SOURCE([[
23 #include <sys/types.h>
26 #include <sys/select.h>
30 struct timeval timeout;
33 return select (0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout) < 0;
34 }]])], [gl_cv_func_select_supports0=yes], [gl_cv_func_select_supports0=no],
38 # Guess no on Interix.
39 interix*) gl_cv_func_select_supports0="guessing no";;
40 # Guess yes otherwise.
41 *) gl_cv_func_select_supports0="guessing yes";;
46 case "$gl_cv_func_select_supports0" in
48 *) REPLACE_SELECT=1 ;;
51 dnl On FreeBSD 8.2, select() doesn't always reject bad fds.
52 AC_CACHE_CHECK([whether select detects invalid fds],
53 [gl_cv_func_select_detects_ebadf],
55 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
56 #include <sys/types.h>
59 # include <sys/select.h>
69 struct timeval timeout;
72 return select (17, &set, NULL, NULL, &timeout) != -1 || errno != EBADF;
73 ]])], [gl_cv_func_select_detects_ebadf=yes],
74 [gl_cv_func_select_detects_ebadf=no],
77 # Guess yes on Linux systems.
78 linux-* | linux) gl_cv_func_select_detects_ebadf="guessing yes" ;;
79 # Guess yes on glibc systems.
80 *-gnu* | gnu*) gl_cv_func_select_detects_ebadf="guessing yes" ;;
81 # If we don't know, assume the worst.
82 *) gl_cv_func_select_detects_ebadf="guessing no" ;;
86 case $gl_cv_func_select_detects_ebadf in
88 *) REPLACE_SELECT=1 ;;
92 dnl Determine the needed libraries.
93 LIB_SELECT="$LIBSOCKET"
94 if test $REPLACE_SELECT = 1; then
97 dnl On the MSVC platform, the function MsgWaitForMultipleObjects
98 dnl (used in lib/select.c) requires linking with -luser32. On mingw,
102 #define WIN32_LEAN_AND_MEAN
107 MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
111 [LIB_SELECT="$LIB_SELECT -luser32"])
115 AC_SUBST([LIB_SELECT])