3 dnl Copyright (C) 2008-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
9 AC_DEFUN([gl_FUNC_GETDTABLESIZE],
11 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
12 AC_REQUIRE([AC_CANONICAL_HOST])
13 AC_CHECK_FUNCS_ONCE([getdtablesize])
14 AC_CHECK_DECLS_ONCE([getdtablesize])
15 if test $ac_cv_func_getdtablesize = yes &&
16 test $ac_cv_have_decl_getdtablesize = yes; then
17 AC_CACHE_CHECK([whether getdtablesize works],
18 [gl_cv_func_getdtablesize_works],
19 [dnl There are two concepts: the "maximum possible file descriptor value + 1"
20 dnl and the "maximum number of open file descriptors in a process".
21 dnl Per SUSv2 and POSIX, getdtablesize() should return the first one.
22 dnl On most platforms, the first and the second concept are the same.
23 dnl On OpenVMS, however, they are different and getdtablesize() returns
24 dnl the second one; thus the test below fails. But we don't care
25 dnl because there's no good way to write a replacement getdtablesize().
27 vms*) gl_cv_func_getdtablesize_works="no (limitation)" ;;
29 dnl Cygwin 1.7.25 automatically increases the RLIMIT_NOFILE soft
30 dnl limit up to an unchangeable hard limit; all other platforms
31 dnl correctly require setrlimit before getdtablesize() can report
35 [[#include <unistd.h>]
38 [[int size = getdtablesize();
39 if (dup2 (0, getdtablesize()) != -1)
41 if (size != getdtablesize())
44 [gl_cv_func_getdtablesize_works=yes],
45 [gl_cv_func_getdtablesize_works=no],
47 cygwin*) # on cygwin 1.5.25, getdtablesize() automatically grows
48 gl_cv_func_getdtablesize_works="guessing no" ;;
49 *) gl_cv_func_getdtablesize_works="guessing yes" ;;
55 case "$gl_cv_func_getdtablesize_works" in
56 *yes | "no (limitation)") ;;
57 *) REPLACE_GETDTABLESIZE=1 ;;
64 # Prerequisites of lib/getdtablesize.c.
65 AC_DEFUN([gl_PREREQ_GETDTABLESIZE], [:])