diff --git a/src/rtlib/unix/fb_unix.h b/src/rtlib/unix/fb_unix.h index 77da48487..474ec6b1c 100644 --- a/src/rtlib/unix/fb_unix.h +++ b/src/rtlib/unix/fb_unix.h @@ -21,6 +21,24 @@ #endif typedef off_t fb_off_t; +#if defined HOST_ANDROID +// __ANDROID_API__ is always defined in newer NDKs, older ones need this header +#include +// Defining _FILE_OFFSET_BITS=64 used to be a no-op until NDK r15. 64-bit offset support in 32-bit targets +// was added to various libc functions over many Android releases, stdio.h mostly in API 24 (Android 7.0). +// See https://android.googlesource.com/platform/bionic/+/refs/heads/main/docs/32-bit-abi.md +// (but note it claims ftello/fseeko didn't exist before API 24, actually they did in older NDKs.) +// On 32-bit targets: +// Older NDK declare ftello/fseeko, and off_t always as a long so ftello/fseeko are 32-bit. +// Newer NDK declare 32-bit ftello/fseeko if _FILE_OFFSET_BITS != 64, +// 64-bit ftello/fseeko if _FILE_OFFSET_BITS == 64 && __ANDROID_API__ >= 24, +// and neither if _FILE_OFFSET_BITS == 64 && __ANDROID_API__ < 24. +#if __ANDROID_API__ < 24 +#define fseeko(stream, offset, whence) fseek(stream, offset, whence) +#define ftello(stream) ftell(stream) +#endif +#endif + FBCALL void fb_BgLock( void ); FBCALL void fb_BgUnlock( void ); #define BG_LOCK() fb_BgLock()