# HG changeset patch # User Paul Eggert # Date 1424151482 28800 # Node ID c513a8c0f5559df5eb349790e18556a5188ff243 # Parent 8e426eb13aae5b6d999e5fd84dab2de7d86dde95 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. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2015-02-16 Paul Eggert + + 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 localename: Implement gl_locale_name_thread_unsafe for Android diff --git a/doc/glibc-functions/getdtablesize.texi b/doc/glibc-functions/getdtablesize.texi --- 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 diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c --- a/lib/getdtablesize.c +++ b/lib/getdtablesize.c @@ -84,7 +84,7 @@ return dtablesize; } -#elif HAVE_GETDTABLESIZE +#elif HAVE_GETDTABLESIZE && HAVE_DECL_GETDTABLESIZE # include # undef getdtablesize diff --git a/m4/dup2.m4 b/m4/dup2.m4 --- 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 #include +#include #include ]], [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 --- 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 -#endif +#include +#include #include #include ]], [[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 --- 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])