getdtablesize.m4 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # getdtablesize.m4 serial 8
  2. dnl Copyright (C) 2008-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([gl_FUNC_GETDTABLESIZE],
  7. [
  8. AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
  9. AC_REQUIRE([AC_CANONICAL_HOST])
  10. AC_CHECK_FUNCS_ONCE([getdtablesize])
  11. AC_CHECK_DECLS_ONCE([getdtablesize])
  12. if test $ac_cv_func_getdtablesize = yes &&
  13. test $ac_cv_have_decl_getdtablesize = yes; then
  14. AC_CACHE_CHECK([whether getdtablesize works],
  15. [gl_cv_func_getdtablesize_works],
  16. [dnl There are two concepts: the "maximum possible file descriptor value + 1"
  17. dnl and the "maximum number of open file descriptors in a process".
  18. dnl Per SUSv2 and POSIX, getdtablesize() should return the first one.
  19. dnl On most platforms, the first and the second concept are the same.
  20. dnl On OpenVMS, however, they are different and getdtablesize() returns
  21. dnl the second one; thus the test below fails. But we don't care
  22. dnl because there's no good way to write a replacement getdtablesize().
  23. case "$host_os" in
  24. vms*) gl_cv_func_getdtablesize_works="no (limitation)" ;;
  25. *)
  26. dnl Cygwin 1.7.25 automatically increases the RLIMIT_NOFILE soft
  27. dnl limit up to an unchangeable hard limit; all other platforms
  28. dnl correctly require setrlimit before getdtablesize() can report
  29. dnl a larger value.
  30. AC_RUN_IFELSE([
  31. AC_LANG_PROGRAM(
  32. [[#include <unistd.h>]
  33. GL_MDA_DEFINES
  34. ],
  35. [[int size = getdtablesize();
  36. if (dup2 (0, getdtablesize()) != -1)
  37. return 1;
  38. if (size != getdtablesize())
  39. return 2;
  40. ]])],
  41. [gl_cv_func_getdtablesize_works=yes],
  42. [gl_cv_func_getdtablesize_works=no],
  43. [case "$host_os" in
  44. cygwin*) # on cygwin 1.5.25, getdtablesize() automatically grows
  45. gl_cv_func_getdtablesize_works="guessing no" ;;
  46. *) gl_cv_func_getdtablesize_works="guessing yes" ;;
  47. esac
  48. ])
  49. ;;
  50. esac
  51. ])
  52. case "$gl_cv_func_getdtablesize_works" in
  53. *yes | "no (limitation)") ;;
  54. *) REPLACE_GETDTABLESIZE=1 ;;
  55. esac
  56. else
  57. HAVE_GETDTABLESIZE=0
  58. fi
  59. ])
  60. # Prerequisites of lib/getdtablesize.c.
  61. AC_DEFUN([gl_PREREQ_GETDTABLESIZE], [:])