diff --git a/compiler-rt/lib/builtins/os_version_check.c b/compiler-rt/lib/builtins/os_version_check.c --- a/compiler-rt/lib/builtins/os_version_check.c +++ b/compiler-rt/lib/builtins/os_version_check.c @@ -216,6 +216,37 @@ return Subminor <= GlobalSubminor; } +#elif __ANDROID__ + +#include +#include +#include +#include + +static int SdkVersion; +static int IsPreRelease; + +static void readSystemProperties(void) { + char buf[PROP_VALUE_MAX]; + + __system_property_get("ro.build.version.sdk", buf); + SdkVersion = atoi(buf); + + __system_property_get("ro.build.version.codename", buf); + IsPreRelease = strcmp(buf, "REL") != 0; + return; +} + +int32_t __isOSVersionAtLeast(int32_t Major, int32_t Minor, int32_t Subminor) { + (int32_t)Minor; + (int32_t)Subminor; + static pthread_once_t once = PTHREAD_ONCE_INIT; + pthread_once(&once, readSystemProperties); + + return SdkVersion >= Major || + (IsPreRelease && Major == __ANDROID_API_FUTURE__); +} + #else // Silence an empty translation unit warning.