Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add documentation (and errno_code()) to system.hpp
[simgrid.git] / include / xbt / system_error.hpp
index f580e75..4a2ae7a 100644 (file)
 namespace simgrid {
 namespace xbt {
 
 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();
 }
 
 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)
 {
 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)
 {
 }
 
 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);
 }
 
 }
 }
 
 }