Skip to content

Commit

Permalink
rtlib/android: fix compiles with NDK r15+, in which fseeko/ftello dis…
Browse files Browse the repository at this point in the history
…appear when targetting API < 24
  • Loading branch information
rversteegen committed Jan 22, 2024
1 parent 13dfe66 commit 30853b9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/rtlib/unix/fb_unix.h
Expand Up @@ -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 <android/api-level.h>
// 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()
Expand Down

0 comments on commit 30853b9

Please sign in to comment.