diff --git a/src/system/Error.hxx b/src/system/Error.hxx index bce69f99..706c1dd8 100644 --- a/src/system/Error.hxx +++ b/src/system/Error.hxx @@ -6,23 +6,10 @@ #include // IWYU pragma: export #include -#include - -template -static inline std::system_error -FormatSystemError(std::error_code code, const char *fmt, - Args&&... args) noexcept -{ - char buffer[1024]; - snprintf(buffer, sizeof(buffer), fmt, std::forward(args)...); - return std::system_error(code, buffer); -} - #ifdef _WIN32 #include // for GetLastError() -#include // for HWND (needed by winbase.h) -#include // for FormatMessageA() +#include /** * Returns the error_category to be used to wrap WIN32 GetLastError() @@ -59,38 +46,10 @@ MakeLastError(const char *msg) noexcept return MakeLastError(GetLastError(), msg); } -template -static inline std::system_error -FormatLastError(DWORD code, const char *fmt, Args&&... args) noexcept -{ - char buffer[512]; - const auto end = buffer + sizeof(buffer); - size_t length = snprintf(buffer, sizeof(buffer) - 128, - fmt, std::forward(args)...); - char *p = buffer + length; - *p++ = ':'; - *p++ = ' '; - - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, code, 0, p, end - p, nullptr); - return MakeLastError(code, buffer); -} - -template -static inline std::system_error -FormatLastError(const char *fmt, Args&&... args) noexcept -{ - return FormatLastError(GetLastError(), fmt, - std::forward(args)...); -} - #endif /* _WIN32 */ #include // IWYU pragma: export -#include - /** * Returns the error_category to be used to wrap errno values. The * C++ standard does not define this well, so this code is based on @@ -127,35 +86,6 @@ MakeErrno(const char *msg) noexcept return MakeErrno(errno, msg); } -template -static inline std::system_error -FormatErrno(int code, const char *fmt, Args&&... args) noexcept -{ - char buffer[512]; - snprintf(buffer, sizeof(buffer), - fmt, std::forward(args)...); - return MakeErrno(code, buffer); -} - -template -static inline std::system_error -FormatErrno(const char *fmt, Args&&... args) noexcept -{ - return FormatErrno(errno, fmt, std::forward(args)...); -} - -template -static inline std::system_error -FormatFileNotFound(const char *fmt, Args&&... args) noexcept -{ -#ifdef _WIN32 - return FormatLastError(ERROR_FILE_NOT_FOUND, fmt, - std::forward(args)...); -#else - return FormatErrno(ENOENT, fmt, std::forward(args)...); -#endif -} - [[gnu::pure]] inline bool IsErrno(const std::system_error &e, int code) noexcept