changeset 17917:c513a8c0f555

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.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 16 Feb 2015 21:38:02 -0800
parents 8e426eb13aae
children a1f80b7d1920
files ChangeLog doc/glibc-functions/getdtablesize.texi lib/getdtablesize.c m4/dup2.m4 m4/fcntl.m4 m4/getdtablesize.m4
diffstat 6 files changed, 45 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2015-02-16  Paul Eggert  <eggert@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  <cernekee@google.com>
 
 	localename: Implement gl_locale_name_thread_unsafe for Android
--- a/doc/glibc-functions/getdtablesize.texi
+++ b/doc/glibc-functions/getdtablesize.texi
@@ -8,7 +8,11 @@
 @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
--- a/lib/getdtablesize.c
+++ b/lib/getdtablesize.c
@@ -84,7 +84,7 @@
   return dtablesize;
 }
 
-#elif HAVE_GETDTABLESIZE
+#elif HAVE_GETDTABLESIZE && HAVE_DECL_GETDTABLESIZE
 
 # include <sys/resource.h>
 # undef getdtablesize
--- 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_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_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)
--- 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_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_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;
--- 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_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 @@
         [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])