X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/33ab7ee0edcb3608e4a3d5deebc2b72c180dbfe4..eb0f65b4fbbea60100b53cb40a1d7138d47ad0d2:/lib/getdtablesize.c diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c index 59b97360bc..03eb7ef1bf 100644 --- a/lib/getdtablesize.c +++ b/lib/getdtablesize.c @@ -84,32 +84,38 @@ getdtablesize (void) return dtablesize; } -#elif HAVE_GETDTABLESIZE +#else +# include # include -# undef getdtablesize -int -rpl_getdtablesize(void) -{ - /* To date, this replacement is only compiled for Cygwin 1.7.25, - which auto-increased the RLIMIT_NOFILE soft limit until it - hits the compile-time constant hard limit of 3200. Although - that version of cygwin supported a child process inheriting - a smaller soft limit, the smaller limit is not enforced, so - we might as well just report the hard limit. */ - struct rlimit lim; - if (!getrlimit (RLIMIT_NOFILE, &lim) && lim.rlim_max != RLIM_INFINITY) - return lim.rlim_max; - return getdtablesize (); -} +# ifndef RLIM_SAVED_CUR +# define RLIM_SAVED_CUR RLIM_INFINITY +# endif +# ifndef RLIM_SAVED_MAX +# define RLIM_SAVED_MAX RLIM_INFINITY +# endif -#elif defined _SC_OPEN_MAX +# ifdef __CYGWIN__ + /* Cygwin 1.7.25 auto-increases the RLIMIT_NOFILE soft limit until it + hits the compile-time constant hard limit of 3200. We might as + well just report the hard limit. */ +# define rlim_cur rlim_max +# endif int getdtablesize (void) { - return sysconf (_SC_OPEN_MAX); + struct rlimit lim; + + if (getrlimit (RLIMIT_NOFILE, &lim) == 0 + && 0 <= lim.rlim_cur && lim.rlim_cur <= INT_MAX + && lim.rlim_cur != RLIM_INFINITY + && lim.rlim_cur != RLIM_SAVED_CUR + && lim.rlim_cur != RLIM_SAVED_MAX) + return lim.rlim_cur; + + return INT_MAX; } #endif