]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Move Win32Util::get_last_ntstatus to util::DirEntry
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 1 Oct 2023 08:26:49 +0000 (10:26 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 1 Oct 2023 17:02:25 +0000 (19:02 +0200)
util::DirEntry is the sole user of Win32Util::get_last_ntstatus.

src/Win32Util.cpp
src/Win32Util.hpp
src/util/DirEntry.cpp

index a32211ff21ed0a30f0ed95769bfec7e84b681a69..f1d4c25b8065d0e1c718b45581abc91979ce4a32 100644 (file)
 #include <chrono>
 #include <thread>
 
-namespace {
-
-template<typename Proc>
-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<Proc*>(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<NTSTATUS NTAPI()>(
-    GetModuleHandleA("ntdll.dll"), "RtlGetLastNtStatus");
-  return get_last_ntstatus_fn();
-}
-
 } // namespace Win32Util
index 5c13f8b2cf7d80019dc44ab95f2e4db96900d195..73112988b1cc7b241250b0159fe12e836a92a83a 100644 (file)
@@ -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
index ced852c1c3fa6d8550e647d87ba93752bb0f914f..e5cfd45b7be3502af770f62b612d355d9ad0b2f1 100644 (file)
@@ -33,6 +33,32 @@ namespace {
 
 #ifdef _WIN32
 
+template<typename Proc>
+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<Proc*>(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<NTSTATUS NTAPI()>(
+    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);
     }