src/corosio/src/detail/make_err.cpp
66.7% Lines (4/6)
100.0% Functions (1/1)
src/corosio/src/detail/make_err.cpp
| Line | Hits | Source Code |
|---|---|---|
| 1 | // | |
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | |
| 3 | // | |
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
| 6 | // | |
| 7 | // Official repository: https://github.com/cppalliance/corosio | |
| 8 | // | |
| 9 | ||
| 10 | #include "src/detail/make_err.hpp" | |
| 11 | ||
| 12 | #include <boost/capy/error.hpp> | |
| 13 | ||
| 14 | #if BOOST_COROSIO_POSIX | |
| 15 | #include <errno.h> | |
| 16 | #else | |
| 17 | #ifndef WIN32_LEAN_AND_MEAN | |
| 18 | #define WIN32_LEAN_AND_MEAN | |
| 19 | #endif | |
| 20 | #include <Windows.h> | |
| 21 | #endif | |
| 22 | ||
| 23 | namespace boost::corosio::detail { | |
| 24 | ||
| 25 | #if BOOST_COROSIO_POSIX | |
| 26 | ||
| 27 | std::error_code | |
| 28 | 9 | make_err(int errn) noexcept |
| 29 | { | |
| 30 | 9 | if (errn == 0) |
| 31 | ✗ | return {}; |
| 32 | ||
| 33 | 9 | if (errn == ECANCELED) |
| 34 | ✗ | return capy::error::canceled; |
| 35 | ||
| 36 | 9 | return std::error_code(errn, std::system_category()); |
| 37 | } | |
| 38 | ||
| 39 | #else | |
| 40 | ||
| 41 | std::error_code | |
| 42 | make_err(unsigned long dwError) noexcept | |
| 43 | { | |
| 44 | if (dwError == 0) | |
| 45 | return {}; | |
| 46 | ||
| 47 | if (dwError == ERROR_OPERATION_ABORTED || dwError == ERROR_CANCELLED) | |
| 48 | return capy::error::canceled; | |
| 49 | ||
| 50 | if (dwError == ERROR_HANDLE_EOF) | |
| 51 | return capy::error::eof; | |
| 52 | ||
| 53 | return std::error_code(static_cast<int>(dwError), std::system_category()); | |
| 54 | } | |
| 55 | ||
| 56 | #endif | |
| 57 | ||
| 58 | } // namespace boost::corosio::detail | |
| 59 |