From 39c0dc69e4769e606c0f2414e481cea698e4111a Mon Sep 17 00:00:00 2001 From: Vladislav Belov Date: Thu, 10 Sep 2026 13:58:28 +0200 Subject: [PATCH] Uses std::filesystem to get a file_size --- source/graphics/MapIO.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/source/graphics/MapIO.cpp b/source/graphics/MapIO.cpp index 8496687cc6..40135ce2ac 100644 --- a/source/graphics/MapIO.cpp +++ b/source/graphics/MapIO.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -56,14 +57,10 @@ Status LoadHeightmapImageOs(const OsPath& filepath, std::vector& heightmap) File file; RETURN_STATUS_IF_ERR(file.Open(OsString(filepath), O_RDONLY)); -#if OS_WIN - // sizeof(long) == 4 on Windows so we can't use lseek. - size_t fileSize = _lseeki64(file.Descriptor(), 0, SEEK_END); - _lseeki64(file.Descriptor(), 0, SEEK_SET); -#else - size_t fileSize = lseek(file.Descriptor(), 0, SEEK_END); - lseek(file.Descriptor(), 0, SEEK_SET); -#endif + std::error_code ec{}; + const size_t fileSize{static_cast(std::filesystem::file_size(filepath.fileSystemPath(), ec))}; + if (ec) + return StatusFromSystemError(ec); std::shared_ptr fileData; RETURN_STATUS_IF_ERR(AllocateAligned(fileData, fileSize, maxSectorSize));