Merge branch 'master' of ssh://git.sv.gnu.org/srv/git/gnutls
[gnutls:gnutls.git] / gl / m4 / select.m4
1 # select.m4 serial 1
2 dnl Copyright (C) 2009 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.
6
7 AC_DEFUN([gl_FUNC_SELECT],
8 [
9   AC_REQUIRE([gl_HEADER_SYS_SELECT])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
11   if test "$ac_cv_header_winsock2_h" = yes; then
12     AC_LIBOBJ([select])
13   else
14     dnl On Interix 3.5, select(0, NULL, NULL, NULL, timeout) fails with error
15     dnl EFAULT.
16     AC_CHECK_HEADERS_ONCE([sys/select.h])
17     AC_CACHE_CHECK([whether select supports a 0 argument],
18       [gl_cv_func_select_supports0],
19       [
20         AC_TRY_RUN([
21 #include <sys/types.h>
22 #include <sys/time.h>
23 #if HAVE_SYS_SELECT_H
24 #include <sys/select.h>
25 #endif
26 int main ()
27 {
28   struct timeval timeout;
29   timeout.tv_sec = 0;
30   timeout.tv_usec = 5;
31   return select (0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout) < 0;
32 }], [gl_cv_func_select_supports0=yes], [gl_cv_func_select_supports0=no],
33           [
34 changequote(,)dnl
35            case "$host_os" in
36                        # Guess no on Interix.
37              interix*) gl_cv_func_select_supports0="guessing no";;
38                        # Guess yes otherwise.
39              *)        gl_cv_func_select_supports0="guessing yes";;
40            esac
41 changequote([,])dnl
42           ])
43       ])
44     case "$gl_cv_func_select_supports0" in
45       *yes) ;;
46       *)
47         REPLACE_SELECT=1
48         AC_LIBOBJ([select])
49         ;;
50     esac
51   fi
52 ])