summaryrefslogtreecommitdiff
path: root/lib/getdtablesize.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-02-20 23:31:17 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2015-02-20 23:32:45 -0800
commit066b17df681fabb40108d719086669957aebbc51 (patch)
tree27f9362ed6a6e68ef6b61925932f84bb1afb37b8 /lib/getdtablesize.c
parent43fb42da8bd6851b5b22d2bbb5d2cd8ceede9c09 (diff)
downloademacs-066b17df681fabb40108d719086669957aebbc51.tar.gz
Merge from gnulib
* doc/misc/texinfo.tex: Update from gnulib. * lib/getdtablesize.c, lib/getopt.c, lib/signal.in.h, lib/tempname.c: * lib/tempname.h, m4/dup2.m4, m4/fcntl.m4, m4/getdtablesize.m4: Update from gnulib, incorporating: 2015-02-20 getdtablesize: port better for Android 2015-02-19 fcntl: Fix cross compiling 2015-02-18 dup2, fcntl: cross-compile better for Android 2015-02-18 getopt: don't crash on memory exhaustion 2015-02-17 tempname: allow compilation with C++ (trivial) 2015-02-17 dup2, fcntl: port to AIX 2015-02-16 getdtablesize, dup2, fcntl: port to Android 2015-02-11 getdtablesize, signal_h: Fix Android build 2015-02-11 maint: various whitespace cleanups in tempname
Diffstat (limited to 'lib/getdtablesize.c')
-rw-r--r--lib/getdtablesize.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c
index 59b97360bc5..bad45f7e32f 100644
--- a/lib/getdtablesize.c
+++ b/lib/getdtablesize.c
@@ -84,32 +84,31 @@ getdtablesize (void)
return dtablesize;
}
-#elif HAVE_GETDTABLESIZE
+#else
+# include <limits.h>
# include <sys/resource.h>
-# undef getdtablesize
+
+# 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
-rpl_getdtablesize(void)
+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 ();
-}
-#elif defined _SC_OPEN_MAX
+ 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;
-int
-getdtablesize (void)
-{
- return sysconf (_SC_OPEN_MAX);
+ return INT_MAX;
}
#endif