select: Simplify replacement idiom.
[gnulib.git] / m4 / select.m4
1 # select.m4 serial 4
2 dnl Copyright (C) 2009-2011 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   AC_REQUIRE([gl_SOCKETS])
12   if test "$ac_cv_header_winsock2_h" = yes; then
13     REPLACE_SELECT=1
14     AC_LIBOBJ([select])
15   else
16     dnl On Interix 3.5, select(0, NULL, NULL, NULL, timeout) fails with error
17     dnl EFAULT.
18     AC_CHECK_HEADERS_ONCE([sys/select.h])
19     AC_CACHE_CHECK([whether select supports a 0 argument],
20       [gl_cv_func_select_supports0],
21       [
22         AC_RUN_IFELSE([AC_LANG_SOURCE([[
23 #include <sys/types.h>
24 #include <sys/time.h>
25 #if HAVE_SYS_SELECT_H
26 #include <sys/select.h>
27 #endif
28 int main ()
29 {
30   struct timeval timeout;
31   timeout.tv_sec = 0;
32   timeout.tv_usec = 5;
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],
35           [
36 changequote(,)dnl
37            case "$host_os" in
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";;
42            esac
43 changequote([,])dnl
44           ])
45       ])
46     case "$gl_cv_func_select_supports0" in
47       *yes) ;;
48       *)
49         REPLACE_SELECT=1
50         AC_LIBOBJ([select])
51         ;;
52     esac
53   fi
54 ])