From 76ddf2528f029c970be3fd1d08659452b1842ae8 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Mon, 18 Apr 2016 14:47:15 +0200 Subject: [PATCH 1/1] Add documentation (and errno_code()) to system.hpp --- include/xbt/system_error.hpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/include/xbt/system_error.hpp b/include/xbt/system_error.hpp index f580e750ce..4a2ae7ae44 100644 --- a/include/xbt/system_error.hpp +++ b/include/xbt/system_error.hpp @@ -14,22 +14,50 @@ namespace simgrid { namespace xbt { +/** A `error_category` suitable to be used with `errno` + * + * It is not clear which error we are supposed to generate + * when getting a errno: + * + * * `system_error` clearly cannot be used for this on Windows; + * + * * `generic_error` might not be used for non-standard `errno`. + * + * Let's just define a function which gives us the correct + * category. + */ inline const std::error_category& errno_category() noexcept { return std::generic_category(); } +/** Create a `error_code` from an `errno` value + * + * This is expected to to whatever is right to create a + * `error_code` from a given `errno` value. + */ +inline +std::error_code errno_code(int errnum) +{ + return std::error_code(errnum, errno_category()); +} + +/** Create a `system_error` from an `errno` value + * + * This is expected to to whatever is right to create a + * `system_error` from a given `errno` value. + */ inline std::system_error errno_error(int errnum) { - return std::system_error(errnum, errno_category()); + return std::system_error(errno_code(errnum)); } inline std::system_error errno_error(int errnum, const char* what) { - return std::system_error(errnum, errno_category(), what); + return std::system_error(errno_code(errnum), what); } } -- 2.20.1