Skip to content

Android Bionic: replace getdtablesize() with #ifdef guard in php_fopen_wrapper.c #11

Description

@EdmondDantes

Problem

getdtablesize() is used unconditionally inside #ifdef HAVE_UNISTD_H in ext/standard/php_fopen_wrapper.c:

#ifdef HAVE_UNISTD_H
    dtablesize = getdtablesize();
#else
    dtablesize = INT_MAX;
#endif

Android Bionic has <unistd.h> (so HAVE_UNISTD_H is defined), but does not expose getdtablesize() — it's a glibc/macOS extension, not in POSIX and not in Bionic.

This causes a compile error when cross-compiling PHP for Android:

ext/standard/php_fopen_wrapper.c:319:16: error: call to undeclared function 'getdtablesize';
ISO C99 and later do not support implicit function declarations

Current workaround

The true-async/releases Android build script applies a sed patch after git clone:

sed -i 's/dtablesize = getdtablesize();/dtablesize = (int)sysconf(_SC_OPEN_MAX);/' \
    ext/standard/php_fopen_wrapper.c

Proper fix

Replace the single call site with an #ifdef guard:

#ifdef HAVE_UNISTD_H
# ifdef HAVE_GETDTABLESIZE
    dtablesize = getdtablesize();
# else
    dtablesize = (int)sysconf(_SC_OPEN_MAX);
# endif
#else
    dtablesize = INT_MAX;
#endif

configure already checks for getdtablesize in some form, or a dedicated AC_CHECK_FUNC(getdtablesize) can be added to ext/standard/config.m4 to set HAVE_GETDTABLESIZE.

sysconf(_SC_OPEN_MAX) is the standard POSIX replacement and works on Android Bionic, Linux, macOS, and all other targets.

Context

  • File: ext/standard/php_fopen_wrapper.c (the php://fd/<N> stream handler)
  • Affects: Android cross-compilation (NDK r27, API 29+)
  • Related: true-async/releases Android build pipeline

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions