Blame m4/getdtablesize.m4

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