// Copyright (c) 2017 Egor Tensin // This file is part of the "PDB repository" project. // For details, see https://github.com/egor-tensin/pdb-repo. // Distributed under the MIT License. #include "pdb/all.hpp" #include #include #include #include #include namespace pdb { namespace file { std::size_t get_size(const std::string& path) { const Handle handle{CreateFileA( path.c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)}; if (handle.get() == INVALID_HANDLE_VALUE) throw error::windows(GetLastError()); LARGE_INTEGER size; if (!GetFileSizeEx(handle.get(), &size)) throw error::windows(GetLastError()); try { const msl::utilities::SafeInt safe_size{size.QuadPart}; return static_cast(safe_size); } catch (const msl::utilities::SafeIntException&) { throw std::range_error{"invalid file size"}; } } } }