The other patches (after your revisions) look good and I installed them, but this one didn't look right. That part of the code really is intended to be used only on Cygwin and it's not portable to other platforms (e.g., it mishandles RLIM_SAVED_MAX). I suppose we could get it to work on Android too but let's not bother. Instead, let's not use Android's getdtablesize since it's obsolescent.

I installed the attached patch instead, which I hope solves the problem in a different way. Please let me know whether it works on Android.
>From b600c3178c1604ff3174986b5fdf033ecb590a66 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Mon, 16 Feb 2015 21:38:02 -0800
Subject: [PATCH] getdtablesize, dup2, fcntl: port to Android

Problem reported by Kevin Cernekee in:
http://lists.gnu.org/archive/html/bug-gnulib/2015-02/msg00092.html
* doc/glibc-functions/getdtablesize.texi (getdtablesize):
Mention that getdtablesize doesn't work on Android.
* lib/getdtablesize.c: Use getrlimit substitute only if
getdtablesize is declared.  This should suffice for Cygwin
while not breaking Android.
* m4/dup2.m4 (gl_FUNC_DUP2):
* m4/fcntl.m4 (gl_FUNC_FCNTL):
Prefer sysconf (_SC_OPEN_MAX) to getdtablesize, as the former is
standardized but the latter is not, and sysconf works on Android.
* m4/getdtablesize.m4 (gl_FUNC_GETDTABLESIZE):
Also check that getdtablesize is declared.
This removes the need for a special case for Android.
---
 ChangeLog                              | 18 ++++++++++++++++++
 doc/glibc-functions/getdtablesize.texi |  6 +++++-
 lib/getdtablesize.c                    |  2 +-
 m4/dup2.m4                             | 13 +++++++------
 m4/fcntl.m4                            | 18 +++++++++---------
 m4/getdtablesize.m4                    | 10 +++++-----
 6 files changed, 45 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b198739..5083e95 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2015-02-16  Paul Eggert  <egg...@cs.ucla.edu>
+
+	getdtablesize, dup2, fcntl: port to Android
+	Problem reported by Kevin Cernekee in:
+	http://lists.gnu.org/archive/html/bug-gnulib/2015-02/msg00092.html
+	* doc/glibc-functions/getdtablesize.texi (getdtablesize):
+	Mention that getdtablesize doesn't work on Android.
+	* lib/getdtablesize.c: Use getrlimit substitute only if
+	getdtablesize is declared.  This should suffice for Cygwin
+	while not breaking Android.
+	* m4/dup2.m4 (gl_FUNC_DUP2):
+	* m4/fcntl.m4 (gl_FUNC_FCNTL):
+	Prefer sysconf (_SC_OPEN_MAX) to getdtablesize, as the former is
+	standardized but the latter is not, and sysconf works on Android.
+	* m4/getdtablesize.m4 (gl_FUNC_GETDTABLESIZE):
+	Also check that getdtablesize is declared.
+	This removes the need for a special case for Android.
+
 2015-02-16  Kevin Cernekee  <cerne...@google.com>
 
 	localename: Implement gl_locale_name_thread_unsafe for Android
diff --git a/doc/glibc-functions/getdtablesize.texi b/doc/glibc-functions/getdtablesize.texi
index c28a546..4c2cc85 100644
--- a/doc/glibc-functions/getdtablesize.texi
+++ b/doc/glibc-functions/getdtablesize.texi
@@ -8,7 +8,11 @@ Portability problems fixed by Gnulib:
 @itemize
 @item
 This function is missing on some platforms:
-mingw, MSVC 9.
+Android LP64, mingw, MSVC 9.
+
+@item
+This function is not declared on some platforms:
+Android LP32.
 
 @item
 This function does not represent the true @code{RLIMIT_NOFILE} soft
diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c
index 59b9736..9fe7462 100644
--- a/lib/getdtablesize.c
+++ b/lib/getdtablesize.c
@@ -84,7 +84,7 @@ getdtablesize (void)
   return dtablesize;
 }
 
-#elif HAVE_GETDTABLESIZE
+#elif HAVE_GETDTABLESIZE && HAVE_DECL_GETDTABLESIZE
 
 # include <sys/resource.h>
 # undef getdtablesize
diff --git a/m4/dup2.m4 b/m4/dup2.m4
index 0354c6a..c47ef27 100644
--- a/m4/dup2.m4
+++ b/m4/dup2.m4
@@ -1,4 +1,4 @@
-#serial 20
+#serial 21
 dnl Copyright (C) 2002, 2005, 2007, 2009-2015 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,7 +8,6 @@ AC_DEFUN([gl_FUNC_DUP2],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
   AC_REQUIRE([AC_CANONICAL_HOST])
-  AC_CHECK_FUNCS_ONCE([getdtablesize])
   m4_ifdef([gl_FUNC_DUP2_OBSOLETE], [
     AC_CHECK_FUNCS_ONCE([dup2])
     if test $ac_cv_func_dup2 = no; then
@@ -22,12 +21,14 @@ AC_DEFUN([gl_FUNC_DUP2],
       [AC_RUN_IFELSE([
          AC_LANG_PROGRAM([[#include <unistd.h>
 #include <fcntl.h>
+#include <limits.h>
 #include <errno.h>]],
            [int result = 0;
-#ifdef HAVE_GETDTABLESIZE
-            int bad_fd = getdtablesize ();
-#else
-            int bad_fd = 1000000;
+            int bad_fd = INT_MAX;
+#ifdef _SC_OPEN_MAX
+            long int open_max = sysconf (_SC_OPEN_MAX);
+            if (0 <= open_max && open_max <= INT_MAX)
+              bad_fd = open_max;
 #endif
 #ifdef FD_CLOEXEC
             if (fcntl (1, F_SETFD, FD_CLOEXEC) == -1)
diff --git a/m4/fcntl.m4 b/m4/fcntl.m4
index 733cd2d..9c044dc 100644
--- a/m4/fcntl.m4
+++ b/m4/fcntl.m4
@@ -1,4 +1,4 @@
-# fcntl.m4 serial 5
+# fcntl.m4 serial 6
 dnl Copyright (C) 2009-2015 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -19,7 +19,7 @@ AC_DEFUN([gl_FUNC_FCNTL],
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
   AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
   AC_REQUIRE([AC_CANONICAL_HOST])
-  AC_CHECK_FUNCS_ONCE([fcntl getdtablesize])
+  AC_CHECK_FUNCS_ONCE([fcntl])
   if test $ac_cv_func_fcntl = no; then
     gl_REPLACE_FCNTL
   else
@@ -28,16 +28,16 @@ AC_DEFUN([gl_FUNC_FCNTL],
     AC_CACHE_CHECK([whether fcntl handles F_DUPFD correctly],
       [gl_cv_func_fcntl_f_dupfd_works],
       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
-#ifdef HAVE_GETDTABLESIZE
-# include <unistd.h>
-#endif
+#include <limits.h>
+#include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 ]], [[int result = 0;
-#ifdef HAVE_GETDTABLESIZE
-      int bad_fd = getdtablesize ();
-#else
-      int bad_fd = 1000000;
+      int bad_fd = INT_MAX;
+#ifdef _SC_OPEN_MAX
+      long int open_max = sysconf (_SC_OPEN_MAX);
+      if (0 <= open_max && open_max <= INT_MAX)
+        bad_fd = open_max;
 #endif
       if (fcntl (0, F_DUPFD, -1) != -1) result |= 1;
       if (errno != EINVAL) result |= 2;
diff --git a/m4/getdtablesize.m4 b/m4/getdtablesize.m4
index 3ad204c..25e9968 100644
--- a/m4/getdtablesize.m4
+++ b/m4/getdtablesize.m4
@@ -1,4 +1,4 @@
-# getdtablesize.m4 serial 5
+# getdtablesize.m4 serial 6
 dnl Copyright (C) 2008-2015 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,7 +9,9 @@ AC_DEFUN([gl_FUNC_GETDTABLESIZE],
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
   AC_REQUIRE([AC_CANONICAL_HOST])
   AC_CHECK_FUNCS_ONCE([getdtablesize])
-  if test $ac_cv_func_getdtablesize = yes; then
+  AC_CHECK_DECLS_ONCE([getdtablesize])
+  if test $ac_cv_func_getdtablesize = yes &&
+     test $ac_cv_have_decl_getdtablesize = yes; then
     # Cygwin 1.7.25 automatically increases the RLIMIT_NOFILE soft limit
     # up to an unchangeable hard limit; all other platforms correctly
     # require setrlimit before getdtablesize() can report a larger value.
@@ -26,9 +28,7 @@ AC_DEFUN([gl_FUNC_GETDTABLESIZE],
         [gl_cv_func_getdtablesize_works=yes],
         [gl_cv_func_getdtablesize_works=no],
         [case "$host_os" in
-          cygwin*|*-android*)
-          # on cygwin 1.5.25, getdtablesize() automatically grows
-          # on Android API level >= 21, the declaration is missing from unistd.h
+          cygwin*) # on cygwin 1.5.25, getdtablesize() automatically grows
             gl_cv_func_getdtablesize_works="guessing no" ;;
           *) gl_cv_func_getdtablesize_works="guessing yes" ;;
          esac])
-- 
2.1.0

Reply via email to