diff options
author | Max Kellermann <max@duempel.org> | 2015-12-18 01:06:12 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-12-18 01:08:16 +0100 |
commit | fe60c52c70705b721bee7fbd6e3aae076a3b99c9 (patch) | |
tree | 931fa53f3cfe9b9e49f2b1555d6669ab00f9b040 /src/system/Error.hxx | |
parent | 93f45904537e2ca9837051fddf4b2b80587d87bf (diff) |
system/Error: add MakeErrno(), MakeLastError()
Diffstat (limited to 'src/system/Error.hxx')
-rw-r--r-- | src/system/Error.hxx | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/system/Error.hxx b/src/system/Error.hxx index 948bb47e5..5a10b6844 100644 --- a/src/system/Error.hxx +++ b/src/system/Error.hxx @@ -49,6 +49,19 @@ FormatSystemError(std::error_code code, const char *fmt, Args&&... args) #include <windows.h> +static inline std::system_error +MakeLastError(DWORD code, const char *msg) +{ + return std::system_error(std::error_code(code, std::system_category()), + msg); +} + +static inline std::system_error +MakeLastError(const char *msg) +{ + return MakeLastError(GetLastError(), msg); +} + template<typename... Args> static inline std::system_error FormatLastError(DWORD code, const char *fmt, Args&&... args) @@ -64,8 +77,7 @@ FormatLastError(DWORD code, const char *fmt, Args&&... args) FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, code, 0, p, end - p, nullptr); - return std::system_error(std::error_code(code, std::system_category()), - buffer); + return MakeLastError(code, buffer); } template<typename... Args> @@ -81,6 +93,19 @@ FormatLastError(const char *fmt, Args&&... args) #include <errno.h> #include <string.h> +static inline std::system_error +MakeErrno(int code, const char *msg) +{ + return std::system_error(std::error_code(code, std::system_category()), + msg); +} + +static inline std::system_error +MakeErrno(const char *msg) +{ + return MakeErrno(errno, msg); +} + template<typename... Args> static inline std::system_error FormatErrno(int code, const char *fmt, Args&&... args) @@ -94,8 +119,7 @@ FormatErrno(int code, const char *fmt, Args&&... args) *p++ = ' '; CopyString(p, strerror(code), end - p); - return std::system_error(std::error_code(code, std::system_category()), - buffer); + return MakeErrno(code, buffer); } template<typename... Args> |