From e6e96c0d895bc273785ef60ca4a57d3db38dc6b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 3 Jul 2017 16:16:25 +0200 Subject: [PATCH] Fix build with NDK 15. This does force us to make do with 32-bit file sizes... --- Common/FileUtil.cpp | 10 ++++++++++ ext/native/file/file_util.cpp | 8 ++++++-- ext/native/file/zip_read.cpp | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Common/FileUtil.cpp b/Common/FileUtil.cpp index 9c061ac535..e6ff88a373 100644 --- a/Common/FileUtil.cpp +++ b/Common/FileUtil.cpp @@ -443,8 +443,13 @@ bool GetFileDetails(const std::string &filename, FileDetails *details) { if (!Exists(filename)) { return false; } +#if __ANDROID__ && __ANDROID_API__ < 21 + struct stat buf; + if (stat(filename.c_str(), &buf) == 0) { +#else struct stat64 buf; if (stat64(filename.c_str(), &buf) == 0) { +#endif details->size = buf.st_size; details->isDirectory = S_ISDIR(buf.st_mode); details->atime = buf.st_atime; @@ -506,9 +511,14 @@ u64 GetFileSize(const std::string &filename) { if (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) return 0; return ((u64)attr.nFileSizeHigh << 32) | (u64)attr.nFileSizeLow; +#else +#if __ANDROID__ && __ANDROID_API__ < 21 + struct stat file_info; + int result = stat(filename.c_str(), &file_info); #else struct stat64 file_info; int result = stat64(filename.c_str(), &file_info); +#endif if (result != 0) { WARN_LOG(COMMON, "GetSize: failed %s: No such file", filename.c_str()); return 0; diff --git a/ext/native/file/file_util.cpp b/ext/native/file/file_util.cpp index ea5dcdc8bc..f81adc3110 100644 --- a/ext/native/file/file_util.cpp +++ b/ext/native/file/file_util.cpp @@ -153,12 +153,16 @@ bool getFileInfo(const char *path, FileInfo *fileInfo) { fileInfo->isWritable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0; fileInfo->exists = true; #else - struct stat64 file_info; std::string copy(path); +#ifdef __ANDROID__ && __ANDROID_API__ < 21 + struct stat file_info; + int result = stat(copy.c_str(), &file_info); +#else + struct stat64 file_info; int result = stat64(copy.c_str(), &file_info); - +#endif if (result < 0) { WLOG("IsDirectory: stat failed on %s", path); fileInfo->exists = false; diff --git a/ext/native/file/zip_read.cpp b/ext/native/file/zip_read.cpp index 4f8dc2b82d..18331630e8 100644 --- a/ext/native/file/zip_read.cpp +++ b/ext/native/file/zip_read.cpp @@ -183,7 +183,7 @@ bool ZipAssetReader::GetFileListing(const char *orig_path, std::vector continue; if (!memcmp(name, path, pathlen)) { // The prefix is right. Let's see if this is a file or path. - char *slashPos = strchr(name + pathlen + 1, '/'); + const char *slashPos = strchr(name + pathlen + 1, '/'); if (slashPos != 0) { // A directory. std::string dirName = std::string(name + pathlen + 1, slashPos - (name + pathlen + 1));