From a6537dd3c853ee41bc7ea8da1915feba1ffd86ff Mon Sep 17 00:00:00 2001 From: Ian Petersen Date: Mon, 30 Oct 2023 15:10:11 -0700 Subject: [PATCH] Format win32/ntapi.cpp --- source/win32/ntapi.cpp | 71 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/source/win32/ntapi.cpp b/source/win32/ntapi.cpp index e025a4801..94e0206e2 100644 --- a/source/win32/ntapi.cpp +++ b/source/win32/ntapi.cpp @@ -21,45 +21,44 @@ #define WIN32_LEAN_AND_MEAN #include -namespace unifex::win32::ntapi -{ - NtCreateFile_t NtCreateFile = nullptr; - NtCancelIoFileEx_t NtCancelIoFileEx = nullptr; - NtReadFile_t NtReadFile = nullptr; - NtWriteFile_t NtWriteFile = nullptr; - NtSetIoCompletion_t NtSetIoCompletion = nullptr; - NtRemoveIoCompletion_t NtRemoveIoCompletion = nullptr; - NtRemoveIoCompletionEx_t NtRemoveIoCompletionEx = nullptr; - RtlNtStatusToDosError_t RtlNtStatusToDosError = nullptr; +namespace unifex::win32::ntapi { +NtCreateFile_t NtCreateFile = nullptr; +NtCancelIoFileEx_t NtCancelIoFileEx = nullptr; +NtReadFile_t NtReadFile = nullptr; +NtWriteFile_t NtWriteFile = nullptr; +NtSetIoCompletion_t NtSetIoCompletion = nullptr; +NtRemoveIoCompletion_t NtRemoveIoCompletion = nullptr; +NtRemoveIoCompletionEx_t NtRemoveIoCompletionEx = nullptr; +RtlNtStatusToDosError_t RtlNtStatusToDosError = nullptr; - static void do_initialisation() noexcept { - HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll"); - if (ntdll == NULL) { +static void do_initialisation() noexcept { + HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll"); + if (ntdll == NULL) { + std::terminate(); + } + + auto init = [&](auto& fnPtr, const char* name) noexcept { + FARPROC p = ::GetProcAddress(ntdll, name); + if (p == NULL) { std::terminate(); } + fnPtr = reinterpret_cast>( + reinterpret_cast(p)); + }; - auto init = [&](auto& fnPtr, const char* name) noexcept { - FARPROC p = ::GetProcAddress(ntdll, name); - if (p == NULL) { - std::terminate(); - } - fnPtr = reinterpret_cast>( - reinterpret_cast(p)); - }; + init(NtCreateFile, "NtCreateFile"); + init(NtCancelIoFileEx, "NtCancelIoFileEx"); + init(NtReadFile, "NtReadFile"); + init(NtWriteFile, "NtWriteFile"); + init(NtSetIoCompletion, "NtSetIoCompletion"); + init(NtRemoveIoCompletion, "NtRemoveIoCompletion"); + init(NtRemoveIoCompletionEx, "NtRemoveIoCompletionEx"); + init(RtlNtStatusToDosError, "RtlNtStatusToDosError"); +} - init(NtCreateFile, "NtCreateFile"); - init(NtCancelIoFileEx, "NtCancelIoFileEx"); - init(NtReadFile, "NtReadFile"); - init(NtWriteFile, "NtWriteFile"); - init(NtSetIoCompletion, "NtSetIoCompletion"); - init(NtRemoveIoCompletion, "NtRemoveIoCompletion"); - init(NtRemoveIoCompletionEx, "NtRemoveIoCompletionEx"); - init(RtlNtStatusToDosError, "RtlNtStatusToDosError"); - } - - void ensure_initialised() noexcept { - static struct initialiser { - initialiser() noexcept { do_initialisation(); } - } dummy; - } +void ensure_initialised() noexcept { + static struct initialiser { + initialiser() noexcept { do_initialisation(); } + } dummy; +} } // namespace unifex::win32::ntapi