Fix bug in last change of m4/sys_select_h.m4.
[gnulib.git] / m4 / sys_select_h.m4
1 # sys_select_h.m4 serial 9
2 dnl Copyright (C) 2006-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_HEADER_SYS_SELECT],
8 [
9   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
10   AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
11   AC_CACHE_CHECK([whether <sys/select.h> is self-contained],
12     [gl_cv_header_sys_select_h_selfcontained],
13     [
14       dnl Test against two bugs:
15       dnl 1. On many platforms, <sys/select.h> assumes prior inclusion of
16       dnl    <sys/types.h>.
17       dnl 2. On OSF/1 4.0, <sys/select.h> provides only a forward declaration
18       dnl    of 'struct timeval', and no definition of this type.
19       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/select.h>]],
20                                          [[struct timeval b;]])],
21         [gl_cv_header_sys_select_h_selfcontained=yes],
22         [gl_cv_header_sys_select_h_selfcontained=no])
23       dnl Test against another bug:
24       dnl 3. On Solaris 10, <sys/select.h> provides an FD_ZERO implementation
25       dnl    that relies on memset(), but without including <string.h>.
26       if test $gl_cv_header_sys_select_h_selfcontained = yes; then
27         AC_COMPILE_IFELSE(
28           [AC_LANG_PROGRAM([[#include <sys/select.h>]],
29                            [[int memset; int bzero;]])
30           ],
31           [AC_LINK_IFELSE(
32              [AC_LANG_PROGRAM([[#include <sys/select.h>]], [[
33                   #undef memset
34                   #define memset nonexistent_memset
35                   extern void *memset (void *, int, unsigned long);
36                   #undef bzero
37                   #define bzero nonexistent_bzero
38                   extern void bzero (void *, unsigned long);
39                   fd_set fds;
40                   FD_ZERO (&fds);
41                 ]])
42              ],
43              [],
44              [gl_cv_header_sys_select_h_selfcontained=no])
45           ])
46       fi
47     ])
48   gl_CHECK_NEXT_HEADERS([sys/select.h])
49   if test $ac_cv_header_sys_select_h = yes; then
50     HAVE_SYS_SELECT_H=1
51   else
52     HAVE_SYS_SELECT_H=0
53   fi
54   AC_SUBST([HAVE_SYS_SELECT_H])
55   if test $gl_cv_header_sys_select_h_selfcontained != yes; then
56     gl_PREREQ_SYS_H_WINSOCK2
57   fi
58 ])
59
60 AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR],
61 [
62   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
63   AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
64   GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
65 ])
66
67 AC_DEFUN([gl_SYS_SELECT_H_DEFAULTS],
68 [
69   GNULIB_SELECT=0; AC_SUBST([GNULIB_SELECT])
70   dnl Assume proper GNU behavior unless another module says otherwise.
71   REPLACE_SELECT=0; AC_SUBST([REPLACE_SELECT])
72 ])