From 40a4bb459d88b1132bf770fe461a93100f5969d5 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sun, 1 Oct 2023 10:26:49 +0200 Subject: [PATCH] refactor: Move Win32Util::get_last_ntstatus to util::DirEntry util::DirEntry is the sole user of Win32Util::get_last_ntstatus. --- src/Win32Util.cpp | 28 ---------------------------- src/Win32Util.hpp | 4 ---- src/util/DirEntry.cpp | 28 +++++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/Win32Util.cpp b/src/Win32Util.cpp index a32211ff2..f1d4c25b8 100644 --- a/src/Win32Util.cpp +++ b/src/Win32Util.cpp @@ -25,26 +25,6 @@ #include #include -namespace { - -template -Proc* -get_proc_address(HMODULE module, const char* proc_name) -{ -#if defined __GNUC__ -# pragma GCC diagnostic push -# if __GNUC__ >= 8 -# pragma GCC diagnostic ignored "-Wcast-function-type" -# endif -#endif - return reinterpret_cast(GetProcAddress(module, proc_name)); -#if defined __GNUC__ -# pragma GCC diagnostic pop -#endif -} - -} // namespace - namespace Win32Util { std::string @@ -125,12 +105,4 @@ argv_to_string(const char* const* argv, return result; } -NTSTATUS -get_last_ntstatus() -{ - static auto* get_last_ntstatus_fn = get_proc_address( - GetModuleHandleA("ntdll.dll"), "RtlGetLastNtStatus"); - return get_last_ntstatus_fn(); -} - } // namespace Win32Util diff --git a/src/Win32Util.hpp b/src/Win32Util.hpp index 5c13f8b2c..73112988b 100644 --- a/src/Win32Util.hpp +++ b/src/Win32Util.hpp @@ -41,10 +41,6 @@ std::string argv_to_string(const char* const* argv, // Return the error message corresponding to `error_code`. std::string error_message(DWORD error_code); -// Returns the last NTSTATUS code. (These can be more specific than the -// corresponding Win32 error code.) -NTSTATUS get_last_ntstatus(); - } // namespace Win32Util #endif diff --git a/src/util/DirEntry.cpp b/src/util/DirEntry.cpp index ced852c1c..e5cfd45b7 100644 --- a/src/util/DirEntry.cpp +++ b/src/util/DirEntry.cpp @@ -33,6 +33,32 @@ namespace { #ifdef _WIN32 +template +Proc* +get_proc_address(HMODULE module, const char* proc_name) +{ +# if defined __GNUC__ +# pragma GCC diagnostic push +# if __GNUC__ >= 8 +# pragma GCC diagnostic ignored "-Wcast-function-type" +# endif +# endif + return reinterpret_cast(GetProcAddress(module, proc_name)); +# if defined __GNUC__ +# pragma GCC diagnostic pop +# endif +} + +// Returns the last NTSTATUS code. (These can be more specific than the +// corresponding Win32 error code.) +NTSTATUS +get_last_ntstatus() +{ + static auto* get_last_ntstatus_fn = get_proc_address( + GetModuleHandleA("ntdll.dll"), "RtlGetLastNtStatus"); + return get_last_ntstatus_fn(); +} + uint16_t win32_file_attributes_to_stat_mode(DWORD attr) { @@ -131,7 +157,7 @@ win32_stat_impl(const char* path, if (handle == INVALID_HANDLE_VALUE) { if (GetLastError() == ERROR_ACCESS_DENIED - && Win32Util::get_last_ntstatus() == STATUS_DELETE_PENDING) { + && get_last_ntstatus() == STATUS_DELETE_PENDING) { // Treat a 'pending delete' as a nonexistent file. SetLastError(ERROR_FILE_NOT_FOUND); } -- 2.47.2