]> Savannah Git Hosting - gnulib.git/commitdiff
getdtablesize: port better for Android
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 20 Feb 2015 18:53:10 +0000 (10:53 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 20 Feb 2015 18:54:03 +0000 (10:54 -0800)
Problem reported by Kevin Cernekee in:
http://lists.gnu.org/archive/html/bug-gnulib/2015-02/msg00112.html
* doc/glibc-functions/getdtablesize.texi (getdtablesize): Mention bug.
* lib/getdtablesize.c (getdtablesize): Don't fall back on _SC_OPEN_MAX.
Instead, just use getrlimit, taking care to avoid Cygwin bug.

dup2, fcntl: cross-compile better for Android

ChangeLog
doc/glibc-functions/getdtablesize.texi
lib/getdtablesize.c

index 6f2118c14974c156f81ceee513555f4b9d2354e5..67ad015fd8538aa76b5962d09a987005967bca92 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2015-02-20  Paul Eggert  <eggert@cs.ucla.edu>
 
+       getdtablesize: port better for Android
+       Problem reported by Kevin Cernekee in:
+       http://lists.gnu.org/archive/html/bug-gnulib/2015-02/msg00112.html
+       * doc/glibc-functions/getdtablesize.texi (getdtablesize): Mention bug.
+       * lib/getdtablesize.c (getdtablesize): Don't fall back on _SC_OPEN_MAX.
+       Instead, just use getrlimit, taking care to avoid Cygwin bug.
+
        poll: fixes for large fds
        * lib/poll.c (poll): Don't check directly for NFD too large.
        Don't rely on undefined behavior in FD_SET when an arg exceeds
@@ -15,7 +22,7 @@
 
 2015-02-18  Paul Eggert  <eggert@cs.ucla.edu>
 
-       dup2, fcntl: cross-compiler better for Android
+       dup2, fcntl: cross-compile better for Android
        Problem reported by Kevin Cernekee in:
        http://lists.gnu.org/archive/html/bug-gnulib/2015-02/msg00109.html
        * m4/dup2.m4 (gl_FUNC_DUP2): Don't guess no when cross-compiling
index 4c2cc856d997f64faf79236a626eb03fc8c48272..f1314f0971e5ee064adccae35f8db15de66c364d 100644 (file)
@@ -17,7 +17,7 @@ Android LP32.
 @item
 This function does not represent the true @code{RLIMIT_NOFILE} soft
 limit on some platforms:
-Cygwin 1.7.25.
+Android LP32, Cygwin 1.7.25.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 9fe74621d410587c798a6fd6ca471d514f3ac4e2..bad45f7e32f94b3ad3e57ffad785fa28de612554 100644 (file)
@@ -84,32 +84,31 @@ getdtablesize (void)
   return dtablesize;
 }
 
-#elif HAVE_GETDTABLESIZE && HAVE_DECL_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