Warn if oat file does end with expected extension
(cherry picked from commit 272df23ebb17297b53a60906304a35bc56eebdd9)
Change-Id: If126ee29811546698f2a8f9bb62300c2a9391017
diff --git a/src/utils.cc b/src/utils.cc
index 03b6172..190cf4a 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -740,6 +740,16 @@
return s.compare(0, strlen(prefix), prefix) == 0;
}
+bool EndsWith(const std::string& s, const char* suffix) {
+ size_t suffix_length = strlen(suffix);
+ size_t string_length = s.size();
+ if (suffix_length > string_length) {
+ return false;
+ }
+ size_t offset = string_length - suffix_length;
+ return s.compare(offset, suffix_length, suffix) == 0;
+}
+
void SetThreadName(const char* thread_name) {
ANNOTATE_THREAD_NAME(thread_name); // For tsan.
@@ -888,11 +898,11 @@
}
bool IsValidDexFilename(const std::string& filename) {
- if (filename.size() < 4) {
- return false;
- }
- std::string suffix(filename.substr(filename.size() - 4));
- return (suffix == ".dex");
+ return EndsWith(filename, ".dex");
+}
+
+bool IsValidOatFilename(const std::string& filename) {
+ return EndsWith(filename, ".oat");
}
} // namespace art