]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gnulib/import/m4/sys_select_h.m4
Update gnulib
[thirdparty/binutils-gdb.git] / gnulib / import / m4 / sys_select_h.m4
CommitLineData
dc6c21da
TT
1# sys_select_h.m4 serial 23
2dnl Copyright (C) 2006-2022 Free Software Foundation, Inc.
d20bc122
MF
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
dc6c21da 7AC_DEFUN_ONCE([gl_SYS_SELECT_H],
d20bc122 8[
d20bc122 9 AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
dc6c21da 10 AC_REQUIRE([AC_C_RESTRICT])
d20bc122
MF
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
36 #ifdef __cplusplus
37 "C"
38 #endif
39 void *memset (void *, int, unsigned long);
40 #undef bzero
41 #define bzero nonexistent_bzero
42 extern
43 #ifdef __cplusplus
44 "C"
45 #endif
46 void bzero (void *, unsigned long);
47 fd_set fds;
48 FD_ZERO (&fds);
49 ]])
50 ],
51 [],
52 [gl_cv_header_sys_select_h_selfcontained=no])
53 ])
54 fi
55 ])
56 dnl <sys/select.h> is always overridden, because of GNULIB_POSIXCHECK.
57 gl_CHECK_NEXT_HEADERS([sys/select.h])
58 if test $ac_cv_header_sys_select_h = yes; then
59 HAVE_SYS_SELECT_H=1
60 else
61 HAVE_SYS_SELECT_H=0
62 fi
63 AC_SUBST([HAVE_SYS_SELECT_H])
64 gl_PREREQ_SYS_H_WINSOCK2
65
66 dnl Check for declarations of anything we want to poison if the
67 dnl corresponding gnulib module is not in use.
68 gl_WARN_ON_USE_PREPARE([[
69/* Some systems require prerequisite headers. */
70#include <sys/types.h>
71#if !(defined __GLIBC__ && !defined __UCLIBC__) && HAVE_SYS_TIME_H
72# include <sys/time.h>
73#endif
74#include <sys/select.h>
75 ]], [pselect select])
76])
77
dc6c21da
TT
78# gl_SYS_SELECT_MODULE_INDICATOR([modulename])
79# sets the shell variable that indicates the presence of the given module
80# to a C preprocessor expression that will evaluate to 1.
81# This macro invocation must not occur in macros that are AC_REQUIREd.
d20bc122
MF
82AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR],
83[
dc6c21da
TT
84 dnl Ensure to expand the default settings once only.
85 gl_SYS_SELECT_H_REQUIRE_DEFAULTS
d20bc122
MF
86 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
87 dnl Define it also as a C macro, for the benefit of the unit tests.
88 gl_MODULE_INDICATOR_FOR_TESTS([$1])
89])
90
dc6c21da
TT
91# Initializes the default values for AC_SUBSTed shell variables.
92# This macro must not be AC_REQUIREd. It must only be invoked, and only
93# outside of macros or in macros that are not AC_REQUIREd.
94AC_DEFUN([gl_SYS_SELECT_H_REQUIRE_DEFAULTS],
95[
96 m4_defun(GL_MODULE_INDICATOR_PREFIX[_SYS_SELECT_H_MODULE_INDICATOR_DEFAULTS], [
97 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PSELECT])
98 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SELECT])
99 ])
100 m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_SELECT_H_MODULE_INDICATOR_DEFAULTS])
101 AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
102])
103
d20bc122
MF
104AC_DEFUN([gl_SYS_SELECT_H_DEFAULTS],
105[
d20bc122
MF
106 dnl Assume proper GNU behavior unless another module says otherwise.
107 HAVE_PSELECT=1; AC_SUBST([HAVE_PSELECT])
108 REPLACE_PSELECT=0; AC_SUBST([REPLACE_PSELECT])
109 REPLACE_SELECT=0; AC_SUBST([REPLACE_SELECT])
110])