From eb8bc865d120676f3a83bf03d1d6df975cffb155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Tue, 19 Apr 2022 20:00:29 +0300 Subject: [PATCH] mdbx: fix and check width of `off_t` for Android. --- src/internals.h | 3 ++- src/lck-posix.c | 7 +++++++ src/osal.h | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/internals.h b/src/internals.h index f0335911..d255a955 100644 --- a/src/internals.h +++ b/src/internals.h @@ -47,7 +47,8 @@ /*----------------------------------------------------------------------------*/ /* Should be defined before any includes */ -#ifndef _FILE_OFFSET_BITS +#if !defined(_FILE_OFFSET_BITS) && !defined(__ANDROID_API__) && \ + !defined(ANDROID) #define _FILE_OFFSET_BITS 64 #endif diff --git a/src/lck-posix.c b/src/lck-posix.c index b3116166..36522ac8 100644 --- a/src/lck-posix.c +++ b/src/lck-posix.c @@ -180,6 +180,13 @@ __cold static void choice_fcntl() { static int lck_op(const mdbx_filehandle_t fd, int cmd, const int lck, const off_t offset, off_t len) { + STATIC_ASSERT(sizeof(off_t) >= sizeof(void *) && + sizeof(off_t) >= sizeof(size_t)); +#ifdef __ANDROID_API__ + STATIC_ASSERT_MSG((sizeof(off_t) * 8 == MDBX_WORDBITS), + "The bitness of system `off_t` type is mismatch. Please " + "fix build and/or NDK configuration."); +#endif /* Android */ mdbx_jitter4testing(true); assert(offset >= 0 && len > 0); assert((uint64_t)offset < (uint64_t)INT64_MAX && diff --git a/src/osal.h b/src/osal.h index c4bbd7b7..ec7b0219 100644 --- a/src/osal.h +++ b/src/osal.h @@ -332,6 +332,14 @@ typedef pthread_mutex_t mdbx_fastmutex_t; #define MDBX_WORDBITS 32 #endif /* MDBX_WORDBITS */ +#if defined(__ANDROID_API__) || defined(ANDROID) +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS != MDBX_WORDBITS +#error "_FILE_OFFSET_BITS != MDBX_WORDBITS" (_FILE_OFFSET_BITS != MDBX_WORDBITS) +#elif defined(__FILE_OFFSET_BITS) && __FILE_OFFSET_BITS != MDBX_WORDBITS +#error "__FILE_OFFSET_BITS != MDBX_WORDBITS" (__FILE_OFFSET_BITS != MDBX_WORDBITS) +#endif +#endif /* Android */ + /*----------------------------------------------------------------------------*/ /* Compiler's includes for builtins/intrinsics */