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
Problem
getdtablesize()is used unconditionally inside#ifdef HAVE_UNISTD_Hinext/standard/php_fopen_wrapper.c:Android Bionic has
<unistd.h>(soHAVE_UNISTD_His defined), but does not exposegetdtablesize()— it's a glibc/macOS extension, not in POSIX and not in Bionic.This causes a compile error when cross-compiling PHP for Android:
Current workaround
The
true-async/releasesAndroid build script applies asedpatch aftergit clone:sed -i 's/dtablesize = getdtablesize();/dtablesize = (int)sysconf(_SC_OPEN_MAX);/' \ ext/standard/php_fopen_wrapper.cProper fix
Replace the single call site with an
#ifdefguard:configurealready checks forgetdtablesizein some form, or a dedicatedAC_CHECK_FUNC(getdtablesize)can be added toext/standard/config.m4to setHAVE_GETDTABLESIZE.sysconf(_SC_OPEN_MAX)is the standard POSIX replacement and works on Android Bionic, Linux, macOS, and all other targets.Context
ext/standard/php_fopen_wrapper.c(thephp://fd/<N>stream handler)true-async/releasesAndroid build pipeline