// SPDX-License-Identifier: BSD-2-Clause // author: Max Kellermann #pragma once #include "system/Error.hxx" // IWYU pragma: export #include #include [[nodiscard]] [[gnu::pure]] std::system_error VFmtSystemError(std::error_code code, fmt::string_view format_str, fmt::format_args args) noexcept; template [[nodiscard]] [[gnu::pure]] std::system_error FmtSystemError(std::error_code code, const S &format_str, Args&&... args) noexcept { return VFmtSystemError(code, format_str, fmt::make_format_args(args...)); } #ifdef _WIN32 [[nodiscard]] [[gnu::pure]] std::system_error VFmtLastError(DWORD code, fmt::string_view format_str, fmt::format_args args) noexcept; template [[nodiscard]] [[gnu::pure]] std::system_error FmtLastError(DWORD code, const S &format_str, Args&&... args) noexcept { return VFmtLastError(code, format_str, fmt::make_format_args(args...)); } template [[nodiscard]] [[gnu::pure]] std::system_error FmtLastError(const S &format_str, Args&&... args) noexcept { return FmtLastError(GetLastError(), format_str, std::forward(args)...); } #endif // _WIN32 [[nodiscard]] [[gnu::pure]] inline std::system_error VFmtErrno(int code, fmt::string_view format_str, fmt::format_args args) noexcept { return VFmtSystemError(std::error_code(code, ErrnoCategory()), format_str, args); } template requires(std::is_convertible_v) [[nodiscard]] [[gnu::pure]] std::system_error FmtErrno(int code, const S &format_str, Args&&... args) noexcept { return FmtSystemError(std::error_code(code, ErrnoCategory()), format_str, std::forward(args)...); } template requires(std::is_convertible_v) [[nodiscard]] [[gnu::pure]] std::system_error FmtErrno(const S &format_str, Args&&... args) noexcept { return FmtErrno(errno, format_str, std::forward(args)...); } template requires(std::is_convertible_v) [[nodiscard]] [[gnu::pure]] std::system_error FmtFileNotFound(const S &format_str, Args&&... args) noexcept { #ifdef _WIN32 return FmtLastError(DWORD{ERROR_FILE_NOT_FOUND}, format_str, std::forward(args)...); #else return FmtErrno(ENOENT, format_str, std::forward(args)...); #endif }