]> Savannah Git Hosting - gnulib.git/commitdiff
getdtablesize, dup2, fcntl: port to Android
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 17 Feb 2015 05:38:02 +0000 (21:38 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 17 Feb 2015 05:40:49 +0000 (21:40 -0800)
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
doc/glibc-functions/getdtablesize.texi
lib/getdtablesize.c
m4/dup2.m4
m4/fcntl.m4
m4/getdtablesize.m4

index b198739dabc7e9a10ed1cc08abee9bbb2d2e6614..5083e95f6b67e49bf76a0a7a1f713fd3796d2c46 100644 (file)
--- 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
index c28a546537b4460956e235b6b9628c47d3e6e591..4c2cc856d997f64faf79236a626eb03fc8c48272 100644 (file)
@@ -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
index 59b97360bc576dce3b5c8f79a1d5b369670c34f1..9fe74621d410587c798a6fd6ca471d514f3ac4e2 100644 (file)
@@ -84,7 +84,7 @@ getdtablesize (void)
   return dtablesize;
 }
 
-#elif HAVE_GETDTABLESIZE
+#elif HAVE_GETDTABLESIZE && HAVE_DECL_GETDTABLESIZE
 
 # include <sys/resource.h>
 # undef getdtablesize
index 0354c6ad478fc65dcc3222a72ef739374cfc4a5c..c47ef2786730db6de6d685d1682d6c7d1dd63b52 100644 (file)
@@ -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)
index 733cd2d701b2d1ee54271dad658b2d544861e515..9c044dca2bb3f81ff632f06b3185b791a19dd7e0 100644 (file)
@@ -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;
index 3ad204c35138189cf97fbed8c925c3fe0a23a414..25e9968947d0cf3703f60a4b86e67151c2846f1d 100644 (file)
@@ -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])