Blame m4/getdtablesize.m4

Packit Service 4684c1
# getdtablesize.m4 serial 7
Packit Service 4684c1
dnl Copyright (C) 2008-2020 Free Software Foundation, Inc.
Packit Service 4684c1
dnl This file is free software; the Free Software Foundation
Packit Service 4684c1
dnl gives unlimited permission to copy and/or distribute it,
Packit Service 4684c1
dnl with or without modifications, as long as this notice is preserved.
Packit Service 4684c1
Packit Service 4684c1
AC_DEFUN([gl_FUNC_GETDTABLESIZE],
Packit Service 4684c1
[
Packit Service 4684c1
  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
Packit Service 4684c1
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit Service 4684c1
  AC_CHECK_FUNCS_ONCE([getdtablesize])
Packit Service 4684c1
  AC_CHECK_DECLS_ONCE([getdtablesize])
Packit Service 4684c1
  if test $ac_cv_func_getdtablesize = yes &&
Packit Service 4684c1
     test $ac_cv_have_decl_getdtablesize = yes; then
Packit Service 4684c1
    AC_CACHE_CHECK([whether getdtablesize works],
Packit Service 4684c1
      [gl_cv_func_getdtablesize_works],
Packit Service 4684c1
      [dnl There are two concepts: the "maximum possible file descriptor value + 1"
Packit Service 4684c1
       dnl and the "maximum number of open file descriptors in a process".
Packit Service 4684c1
       dnl Per SUSv2 and POSIX, getdtablesize() should return the first one.
Packit Service 4684c1
       dnl On most platforms, the first and the second concept are the same.
Packit Service 4684c1
       dnl On OpenVMS, however, they are different and getdtablesize() returns
Packit Service 4684c1
       dnl the second one; thus the test below fails. But we don't care
Packit Service 4684c1
       dnl because there's no good way to write a replacement getdtablesize().
Packit Service 4684c1
       case "$host_os" in
Packit Service 4684c1
         vms*) gl_cv_func_getdtablesize_works="no (limitation)" ;;
Packit Service 4684c1
         *)
Packit Service 4684c1
           dnl Cygwin 1.7.25 automatically increases the RLIMIT_NOFILE soft
Packit Service 4684c1
           dnl limit up to an unchangeable hard limit; all other platforms
Packit Service 4684c1
           dnl correctly require setrlimit before getdtablesize() can report
Packit Service 4684c1
           dnl a larger value.
Packit Service 4684c1
           AC_RUN_IFELSE([
Packit Service 4684c1
             AC_LANG_PROGRAM([[#include <unistd.h>]],
Packit Service 4684c1
               [int size = getdtablesize();
Packit Service 4684c1
                if (dup2 (0, getdtablesize()) != -1)
Packit Service 4684c1
                  return 1;
Packit Service 4684c1
                if (size != getdtablesize())
Packit Service 4684c1
                  return 2;
Packit Service 4684c1
               ])],
Packit Service 4684c1
             [gl_cv_func_getdtablesize_works=yes],
Packit Service 4684c1
             [gl_cv_func_getdtablesize_works=no],
Packit Service 4684c1
             [case "$host_os" in
Packit Service 4684c1
                cygwin*) # on cygwin 1.5.25, getdtablesize() automatically grows
Packit Service 4684c1
                  gl_cv_func_getdtablesize_works="guessing no" ;;
Packit Service 4684c1
                *) gl_cv_func_getdtablesize_works="guessing yes" ;;
Packit Service 4684c1
              esac
Packit Service 4684c1
             ])
Packit Service 4684c1
           ;;
Packit Service 4684c1
       esac
Packit Service 4684c1
      ])
Packit Service 4684c1
    case "$gl_cv_func_getdtablesize_works" in
Packit Service 4684c1
      *yes | "no (limitation)") ;;
Packit Service 4684c1
      *) REPLACE_GETDTABLESIZE=1 ;;
Packit Service 4684c1
    esac
Packit Service 4684c1
  else
Packit Service 4684c1
    HAVE_GETDTABLESIZE=0
Packit Service 4684c1
  fi
Packit Service 4684c1
])
Packit Service 4684c1
Packit Service 4684c1
# Prerequisites of lib/getdtablesize.c.
Packit Service 4684c1
AC_DEFUN([gl_PREREQ_GETDTABLESIZE], [:])