diff --git a/src/util/bootstrap.cpp b/src/util/bootstrap.cpp index b5b018e..66fbde0 100644 --- a/src/util/bootstrap.cpp +++ b/src/util/bootstrap.cpp @@ -116,6 +116,13 @@ static std::uint64_t satAdd(std::uint64_t a, std::uint64_t b) { return (a > UINT64_MAX - b) ? UINT64_MAX : a + b; } +// fs::file_size is 64-bit on every platform; ftell() returns a 32-bit long on Win LLP64. +static long long fileSizeOrZero(const std::string& path) { + std::error_code ec; + auto sz = fs::file_size(path, ec); + return ec ? 0 : (long long)sz; +} + static std::string lowerAscii(std::string s) { for (char& c : s) if (c >= 'A' && c <= 'Z') c = static_cast(c - 'A' + 'a'); @@ -924,10 +931,8 @@ std::string Bootstrap::computeSHA256(const std::string& filePath, float pctBase, FILE* fp = fopen(filePath.c_str(), "rb"); if (!fp) return {}; - // Get file size for progress reporting - fseek(fp, 0, SEEK_END); - long long fileSize = ftell(fp); - fseek(fp, 0, SEEK_SET); + // File size for progress reporting (not a seek: ftell is 32-bit on Windows LLP64). + const long long fileSize = fileSizeOrZero(filePath); crypto_hash_sha256_state state; crypto_hash_sha256_init(&state); @@ -1061,10 +1066,8 @@ std::string Bootstrap::computeMD5(const std::string& filePath, float pctBase, fl FILE* fp = fopen(filePath.c_str(), "rb"); if (!fp) return {}; - // Get file size for progress reporting - fseek(fp, 0, SEEK_END); - long long fileSize = ftell(fp); - fseek(fp, 0, SEEK_SET); + // File size for progress reporting (not a seek: ftell is 32-bit on Windows LLP64). + const long long fileSize = fileSizeOrZero(filePath); MD5Context ctx; md5_init(&ctx);