diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2020-01-14 19:36:53 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2020-01-14 20:07:47 +0300 |
commit | 0bff1d2776e0da589dd98eca69e7f04fb07dfd02 (patch) | |
tree | f7f8b905a34133d80e93d20770bdb092c04e247d /src/utils | |
parent | clang-format: don't BinPackArguments (diff) | |
download | winapi-debug-0bff1d2776e0da589dd98eca69e7f04fb07dfd02.tar.gz winapi-debug-0bff1d2776e0da589dd98eca69e7f04fb07dfd02.zip |
clang-format all the code
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/file.cpp | 110 |
1 files changed, 50 insertions, 60 deletions
diff --git a/src/utils/file.cpp b/src/utils/file.cpp index c0bb4bd..c25307a 100644 --- a/src/utils/file.cpp +++ b/src/utils/file.cpp @@ -5,70 +5,60 @@ #include "pdb/all.hpp" -#include <safeint.h> - #include <Windows.h> +#include <safeint.h> #include <cstddef> - #include <stdexcept> #include <string> -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()); - - std::size_t result = 0; - - if (!msl::utilities::SafeCast(size.QuadPart, result)) - throw std::runtime_error{"invalid file size"}; - - return result; - } - - ID query_id(const std::string& path) - { - const Handle handle{CreateFileA( - 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 error::windows(GetLastError()); - - FILE_ID_INFO id; - - if (!GetFileInformationByHandleEx( - handle.get(), - FileIdInfo, - &id, - sizeof(id))) - throw error::windows(GetLastError()); - - return {id}; - } - } +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()); + + std::size_t result = 0; + + if (!msl::utilities::SafeCast(size.QuadPart, result)) + throw std::runtime_error{"invalid file size"}; + + return result; } + +ID query_id(const std::string& path) { + const Handle handle{CreateFileA(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 error::windows(GetLastError()); + + FILE_ID_INFO id; + + if (!GetFileInformationByHandleEx(handle.get(), FileIdInfo, &id, sizeof(id))) + throw error::windows(GetLastError()); + + return {id}; +} + +} // namespace file +} // namespace pdb |