[PATCH] D86596: Implement __isOSVersionAtLeast for Android

Stephen Hines via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 12:55:50 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG516a01b5f36d: Implement __isOSVersionAtLeast for Android (authored by srhines).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86596/new/

https://reviews.llvm.org/D86596

Files:
  compiler-rt/lib/builtins/os_version_check.c


Index: compiler-rt/lib/builtins/os_version_check.c
===================================================================
--- compiler-rt/lib/builtins/os_version_check.c
+++ compiler-rt/lib/builtins/os_version_check.c
@@ -216,6 +216,44 @@
   return Subminor <= GlobalSubminor;
 }
 
+#elif __ANDROID__
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/system_properties.h>
+
+static int SdkVersion;
+static int IsPreRelease;
+
+static void readSystemProperties(void) {
+  char buf[PROP_VALUE_MAX];
+
+  if (__system_property_get("ro.build.version.sdk", buf) == 0) {
+    // When the system property doesn't exist, defaults to future API level.
+    SdkVersion = __ANDROID_API_FUTURE__;
+  } else {
+    SdkVersion = atoi(buf);
+  }
+
+  if (__system_property_get("ro.build.version.codename", buf) == 0) {
+    IsPreRelease = 1;
+  } else {
+    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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86596.292006.patch
Type: text/x-patch
Size: 1310 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200915/7207da3f/attachment.bin>


More information about the llvm-commits mailing list