From: Joel Rosdahl Date: Mon, 2 Oct 2023 18:45:02 +0000 (+0200) Subject: refactor: Move Win32Util::error_message to util X-Git-Tag: v4.9~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72100062452ee226d80627b6d47a655eb3193e13;p=thirdparty%2Fccache.git refactor: Move Win32Util::error_message to util --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c6dc1178..a61428d44 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,9 +25,7 @@ if(MTR_ENABLED) list(APPEND source_files MiniTrace.cpp) endif() -if(WIN32) - list(APPEND source_files Win32Util.cpp) -else() +if(NOT WIN32) list(APPEND source_files SignalHandler.cpp) endif() diff --git a/src/Context.cpp b/src/Context.cpp index fbbfb2fde..76768013f 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -23,7 +23,6 @@ #include "Util.hpp" #include "hashutil.hpp" -#include #include #include #include diff --git a/src/Logging.cpp b/src/Logging.cpp index 1705024d7..a681c06b6 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -21,7 +21,6 @@ #include "Config.hpp" #include "Util.hpp" -#include "Win32Util.hpp" #include "execute.hpp" #include diff --git a/src/Util.cpp b/src/Util.cpp index 79b91af9a..aad8a6065 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -21,7 +21,6 @@ #include "Config.hpp" #include "Context.hpp" #include "Logging.hpp" -#include "Win32Util.hpp" #include #include diff --git a/src/ccache.cpp b/src/ccache.cpp index d6e6a27cd..51d2a4230 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -28,7 +28,6 @@ #include "MiniTrace.hpp" #include "SignalHandler.hpp" #include "Util.hpp" -#include "Win32Util.hpp" #include "argprocessing.hpp" #include "compopt.hpp" #include "execute.hpp" diff --git a/src/execute.cpp b/src/execute.cpp index 6c52fa874..80b5c2766 100644 --- a/src/execute.cpp +++ b/src/execute.cpp @@ -24,7 +24,6 @@ #include "Logging.hpp" #include "SignalHandler.hpp" #include "Util.hpp" -#include "Win32Util.hpp" #include #include @@ -32,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -122,7 +122,7 @@ win32execute(const char* path, if (!job_success) { DWORD error = GetLastError(); LOG("failed to IsProcessInJob: {} ({})", - Win32Util::error_message(error), + util::win32_error_message(error), error); return 0; } @@ -137,7 +137,7 @@ win32execute(const char* path, if (!querySuccess) { DWORD error = GetLastError(); LOG("failed to QueryInformationJobObject: {} ({})", - Win32Util::error_message(error), + util::win32_error_message(error), error); return 0; } @@ -160,7 +160,7 @@ win32execute(const char* path, if (job == nullptr) { DWORD error = GetLastError(); LOG("failed to CreateJobObject: {} ({})", - Win32Util::error_message(error), + util::win32_error_message(error), error); return -1; } @@ -176,7 +176,7 @@ win32execute(const char* path, if (!job_success) { DWORD error = GetLastError(); LOG("failed to JobObjectExtendedLimitInformation: {} ({})", - Win32Util::error_message(error), + util::win32_error_message(error), error); return -1; } @@ -253,7 +253,7 @@ win32execute(const char* path, DWORD error = GetLastError(); LOG("failed to execute {}: {} ({})", full_path, - Win32Util::error_message(error), + util::win32_error_message(error), error); return -1; } @@ -265,7 +265,7 @@ win32execute(const char* path, DWORD error = GetLastError(); LOG("failed to assign process to job object {}: {} ({})", full_path, - Win32Util::error_message(error), + util::win32_error_message(error), error); return -1; } diff --git a/src/hashutil.cpp b/src/hashutil.cpp index 7665c4e00..56ee51c3f 100644 --- a/src/hashutil.cpp +++ b/src/hashutil.cpp @@ -22,7 +22,6 @@ #include "Config.hpp" #include "Context.hpp" #include "Logging.hpp" -#include "Win32Util.hpp" #include "execute.hpp" #include "macroskip.hpp" diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index c22a0eec5..b9020bbfc 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -12,6 +12,7 @@ set( UmaskScope.cpp assertions.cpp environment.cpp + error.cpp file.cpp filesystem.cpp path.cpp diff --git a/src/util/DirEntry.cpp b/src/util/DirEntry.cpp index e5cfd45b7..beeb90c2f 100644 --- a/src/util/DirEntry.cpp +++ b/src/util/DirEntry.cpp @@ -19,7 +19,6 @@ #include "DirEntry.hpp" #include -#include #include #include #include diff --git a/src/util/LockFile.cpp b/src/util/LockFile.cpp index c3f670e90..f922d71c1 100644 --- a/src/util/LockFile.cpp +++ b/src/util/LockFile.cpp @@ -20,10 +20,10 @@ #include "Logging.hpp" #include "Util.hpp" -#include "Win32Util.hpp" #include #include +#include #include #include #include @@ -386,7 +386,7 @@ LockFile::do_acquire(const bool blocking) LOG("Could not acquire {}: {} ({})", m_lock_file, - Win32Util::error_message(error), + util::win32_error_message(error), error); // ERROR_SHARING_VIOLATION: lock already held. diff --git a/src/Win32Util.cpp b/src/util/error.cpp similarity index 88% rename from src/Win32Util.cpp rename to src/util/error.cpp index d50a4bd63..5cc9c346b 100644 --- a/src/Win32Util.cpp +++ b/src/util/error.cpp @@ -16,19 +16,16 @@ // this program; if not, write to the Free Software Foundation, Inc., 51 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -#include "Win32Util.hpp" +#include "error.hpp" -#include "Util.hpp" +#include -#include +namespace util { -#include -#include - -namespace Win32Util { +#ifdef _WIN32 std::string -error_message(DWORD error_code) +win32_error_message(uint32_t error_code) { LPSTR buffer; size_t size = @@ -49,4 +46,6 @@ error_message(DWORD error_code) return message; } -} // namespace Win32Util +#endif + +} // namespace util diff --git a/src/Win32Util.hpp b/src/util/error.hpp similarity index 80% rename from src/Win32Util.hpp rename to src/util/error.hpp index b73224090..de77b77c7 100644 --- a/src/Win32Util.hpp +++ b/src/util/error.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2023 Joel Rosdahl and other contributors +// Copyright (C) 2023 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,17 +18,16 @@ #pragma once -#ifdef _WIN32 - -# include +#include +#include -# include +namespace util { -namespace Win32Util { +#ifdef _WIN32 // Return the error message corresponding to `error_code`. -std::string error_message(DWORD error_code); - -} // namespace Win32Util +std::string win32_error_message(uint32_t error_code); #endif + +} // namespace util diff --git a/src/util/file.cpp b/src/util/file.cpp index fdc211214..ff97c2398 100644 --- a/src/util/file.cpp +++ b/src/util/file.cpp @@ -19,12 +19,12 @@ #include "file.hpp" #include -#include #include #include #include #include #include +#include #include #include #include @@ -306,7 +306,7 @@ read_file(const fs::path& path, size_t size_hint) return tl::unexpected( FMT("Failed to convert {} from UTF-16LE to UTF-8: {}", path, - Win32Util::error_message(GetLastError()))); + util::win32_error_message(GetLastError()))); } result = std::string(size, '\0');