From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DE8BA3954C7C; Thu, 18 Jun 2020 18:27:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE8BA3954C7C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592504823; bh=IzbDacaHvdz+QsPowiffZi0pXH6OHEkrJ64V5uNHpcg=; h=From:To:Subject:Date:From; b=Hlc4Fl0q2xszTd1pjp85hcnNSa1rp0VvHSKXlUtevpZ7elymoQxFxxejtVVNzu3a4 Pe3lt2DG2H1fcZqLjVyz4YI0BvBpq9mwYz0PVXGGCYtACLP7eM1D9lcE8CM8XQeB0D DDR7EUBEcjioVBfsR/wSR+gwagG5tGR9YZr+ndjw= From: "reiter.christoph at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/95749] New: std::filesystem::file_size returns wrong size for large files on Windows Date: Thu, 18 Jun 2020 18:27:03 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: reiter.christoph at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jun 2020 18:27:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95749 Bug ID: 95749 Summary: std::filesystem::file_size returns wrong size for large files on Windows Product: gcc Version: 10.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: reiter.christoph at gmail dot com Target Milestone: --- Downstream report: https://github.com/msys2/MINGW-packages/issues/6585 ---- #include #include #include #include #include int main(int argc, char** argv) { uint64_t std_filesystem_file_size; uint64_t std_fstream_file_size; std::filesystem::path sourceFile =3D std::filesystem::current_path() / "example_3GiB.bin"; std::ofstream ofs(sourceFile); ofs << "this is some text in the new file\n"; ofs.close(); std::filesystem::resize_file(sourceFile,3221225472); std_filesystem_file_size =3D std::filesystem::file_size(sourceFile); std::ifstream in(sourceFile.string(), std::ifstream::ate | std::ifstream::binary); std_fstream_file_size =3D in.tellg(); std::cout << "3 GiB file:" << std::endl; std::cout << "std_filesystem_file_size: " << std_filesystem_file_size << std::endl; std::cout << "std_fstream_file_size: " << std_fstream_file_size << std::endl; return 0; } ---- $ g++ -std=3Dc++17 a.cpp $ ./a.exe 3 GiB file: std_filesystem_file_size: 18446744072635809792 std_fstream_file_size: 3221225472 ---- The first value is wrong. My uneducated guess would be that https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c325581= 4b16/libstdc%2B%2B-v3/src/filesystem/ops-common.h#L66 should use _wstat64() instead of _wstat and stat_type should be _stat64 ins= tead of _stat, otherwise things are limited to 32bit. See https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-funct= ions?view=3Dvs-2019 for details.=