libs/corosio/src/corosio/src/detail/make_err.cpp
66.7% Lines (4/6)
100.0% Functions (1/1)
50.0% Branches (2/4)
libs/corosio/src/corosio/src/detail/make_err.cpp
| Line | Branch | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot 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 | 21 | make_err(int errn) noexcept | |
| 29 | { | ||
| 30 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (errn == 0) |
| 31 | ✗ | return {}; | |
| 32 | |||
| 33 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (errn == ECANCELED) |
| 34 | ✗ | return capy::error::canceled; | |
| 35 | |||
| 36 | 21 | 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 || | ||
| 48 | dwError == ERROR_CANCELLED) | ||
| 49 | return capy::error::canceled; | ||
| 50 | |||
| 51 | if (dwError == ERROR_HANDLE_EOF) | ||
| 52 | return capy::error::eof; | ||
| 53 | |||
| 54 | return std::error_code( | ||
| 55 | static_cast<int>(dwError), | ||
| 56 | std::system_category()); | ||
| 57 | } | ||
| 58 | |||
| 59 | #endif | ||
| 60 | |||
| 61 | } // namespace boost::corosio::detail | ||
| 62 |