From de5c928779d69e22221d08c21ce3b5455157004e Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 16 May 2021 01:21:58 +0300 Subject: export pdb::file to winapi-common's File --- src/dbghelp.cpp | 3 ++- src/repo.cpp | 4 +++- src/utils/file.cpp | 64 ------------------------------------------------------ 3 files changed, 5 insertions(+), 66 deletions(-) delete mode 100644 src/utils/file.cpp (limited to 'src') diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp index fb94835..d42c900 100644 --- a/src/dbghelp.cpp +++ b/src/dbghelp.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -127,7 +128,7 @@ ModuleInfo DbgHelp::load_pdb(const std::string& path) const { DWORD size = 0; { - const auto raw_size = file::get_size(path); + const auto raw_size = winapi::File::open_read_attributes(path).get_size(); if (raw_size > std::numeric_limits::max()) throw std::range_error{"PDB file is too large"}; size = static_cast(raw_size); diff --git a/src/repo.cpp b/src/repo.cpp index af56373..610ef9a 100644 --- a/src/repo.cpp +++ b/src/repo.cpp @@ -5,6 +5,8 @@ #include +#include + #include #include #include @@ -89,7 +91,7 @@ Address Repo::add_pdb(Address online_base, const std::string& path) { if (online_bases.find(online_base) != online_bases.cend()) throw std::runtime_error{pdb_already_loaded(online_base, path)}; - auto file_id = file::query_id(path); + auto file_id = winapi::File::open_read_attributes(path).query_id(); if (file_ids.find(file_id) != file_ids.cend()) throw std::runtime_error{pdb_already_loaded(path)}; diff --git a/src/utils/file.cpp b/src/utils/file.cpp deleted file mode 100644 index fdc695f..0000000 --- a/src/utils/file.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2017 Egor Tensin -// This file is part of the "winapi-debug" project. -// For details, see https://github.com/egor-tensin/winapi-debug. -// Distributed under the MIT License. - -#include - -#include -#include - -#include - -#include -#include -#include -#include - -namespace pdb { -namespace file { - -std::size_t get_size(const std::string& path) { - const Handle handle{CreateFileW(winapi::widen(path).c_str(), - FILE_READ_ATTRIBUTES, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL)}; - - if (handle.get() == INVALID_HANDLE_VALUE) - throw winapi::error::windows(GetLastError(), "CreateFileW"); - - LARGE_INTEGER size; - - if (!GetFileSizeEx(handle.get(), &size)) - throw winapi::error::windows(GetLastError(), "GetFileSizeEx"); - - if (size.QuadPart < 0 || size.QuadPart > SIZE_MAX) - throw std::runtime_error{"invalid file size"}; - return static_cast(size.QuadPart); -} - -ID query_id(const std::string& path) { - const Handle handle{CreateFileW(winapi::widen(path).c_str(), - FILE_READ_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL)}; - - if (handle.get() == INVALID_HANDLE_VALUE) - throw winapi::error::windows(GetLastError(), "CreateFileW"); - - FILE_ID_INFO id; - - if (!GetFileInformationByHandleEx(handle.get(), FileIdInfo, &id, sizeof(id))) - throw winapi::error::windows(GetLastError(), "GetFileInformationByHandleEx"); - - return {id}; -} - -} // namespace file -} // namespace pdb -- cgit v1.2.3