sys_select_h.m4 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # sys_select_h.m4 serial 23
  2. dnl Copyright (C) 2006-2023 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. AC_DEFUN_ONCE([gl_SYS_SELECT_H],
  7. [
  8. AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
  9. AC_REQUIRE([AC_C_RESTRICT])
  10. AC_CACHE_CHECK([whether <sys/select.h> is self-contained],
  11. [gl_cv_header_sys_select_h_selfcontained],
  12. [
  13. dnl Test against two bugs:
  14. dnl 1. On many platforms, <sys/select.h> assumes prior inclusion of
  15. dnl <sys/types.h>.
  16. dnl 2. On OSF/1 4.0, <sys/select.h> provides only a forward declaration
  17. dnl of 'struct timeval', and no definition of this type.
  18. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/select.h>]],
  19. [[struct timeval b;]])],
  20. [gl_cv_header_sys_select_h_selfcontained=yes],
  21. [gl_cv_header_sys_select_h_selfcontained=no])
  22. dnl Test against another bug:
  23. dnl 3. On Solaris 10, <sys/select.h> provides an FD_ZERO implementation
  24. dnl that relies on memset(), but without including <string.h>.
  25. if test $gl_cv_header_sys_select_h_selfcontained = yes; then
  26. AC_COMPILE_IFELSE(
  27. [AC_LANG_PROGRAM([[#include <sys/select.h>]],
  28. [[int memset; int bzero;]])
  29. ],
  30. [AC_LINK_IFELSE(
  31. [AC_LANG_PROGRAM([[#include <sys/select.h>]], [[
  32. #undef memset
  33. #define memset nonexistent_memset
  34. extern
  35. #ifdef __cplusplus
  36. "C"
  37. #endif
  38. void *memset (void *, int, unsigned long);
  39. #undef bzero
  40. #define bzero nonexistent_bzero
  41. extern
  42. #ifdef __cplusplus
  43. "C"
  44. #endif
  45. void bzero (void *, unsigned long);
  46. fd_set fds;
  47. FD_ZERO (&fds);
  48. ]])
  49. ],
  50. [],
  51. [gl_cv_header_sys_select_h_selfcontained=no])
  52. ])
  53. fi
  54. ])
  55. dnl <sys/select.h> is always overridden, because of GNULIB_POSIXCHECK.
  56. gl_CHECK_NEXT_HEADERS([sys/select.h])
  57. if test $ac_cv_header_sys_select_h = yes; then
  58. HAVE_SYS_SELECT_H=1
  59. else
  60. HAVE_SYS_SELECT_H=0
  61. fi
  62. AC_SUBST([HAVE_SYS_SELECT_H])
  63. gl_PREREQ_SYS_H_WINSOCK2
  64. dnl Check for declarations of anything we want to poison if the
  65. dnl corresponding gnulib module is not in use.
  66. gl_WARN_ON_USE_PREPARE([[
  67. /* Some systems require prerequisite headers. */
  68. #include <sys/types.h>
  69. #if !(defined __GLIBC__ && !defined __UCLIBC__) && HAVE_SYS_TIME_H
  70. # include <sys/time.h>
  71. #endif
  72. #include <sys/select.h>
  73. ]], [pselect select])
  74. ])
  75. # gl_SYS_SELECT_MODULE_INDICATOR([modulename])
  76. # sets the shell variable that indicates the presence of the given module
  77. # to a C preprocessor expression that will evaluate to 1.
  78. # This macro invocation must not occur in macros that are AC_REQUIREd.
  79. AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR],
  80. [
  81. dnl Ensure to expand the default settings once only.
  82. gl_SYS_SELECT_H_REQUIRE_DEFAULTS
  83. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  84. dnl Define it also as a C macro, for the benefit of the unit tests.
  85. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  86. ])
  87. # Initializes the default values for AC_SUBSTed shell variables.
  88. # This macro must not be AC_REQUIREd. It must only be invoked, and only
  89. # outside of macros or in macros that are not AC_REQUIREd.
  90. AC_DEFUN([gl_SYS_SELECT_H_REQUIRE_DEFAULTS],
  91. [
  92. m4_defun(GL_MODULE_INDICATOR_PREFIX[_SYS_SELECT_H_MODULE_INDICATOR_DEFAULTS], [
  93. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PSELECT])
  94. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SELECT])
  95. ])
  96. m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_SELECT_H_MODULE_INDICATOR_DEFAULTS])
  97. AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
  98. ])
  99. AC_DEFUN([gl_SYS_SELECT_H_DEFAULTS],
  100. [
  101. dnl Assume proper GNU behavior unless another module says otherwise.
  102. HAVE_PSELECT=1; AC_SUBST([HAVE_PSELECT])
  103. REPLACE_PSELECT=0; AC_SUBST([REPLACE_PSELECT])
  104. REPLACE_SELECT=0; AC_SUBST([REPLACE_SELECT])
  105. ])