| 1 | // SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 | // SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> |
| 3 | |
| 4 | #include <map> |
| 5 | #include <stdexcept> |
| 6 | #include <system_error> |
| 7 | |
| 8 | #include "internal.hpp" |
| 9 | |
| 10 | namespace gpiod { |
| 11 | |
| 12 | void throw_from_errno(const ::std::string& what) |
| 13 | { |
| 14 | switch (errno) { |
| 15 | case EINVAL: |
| 16 | throw ::std::invalid_argument(what); |
| 17 | case E2BIG: |
| 18 | throw ::std::length_error(what); |
| 19 | case ENOMEM: |
| 20 | throw ::std::bad_alloc(); |
| 21 | case EDOM: |
| 22 | throw ::std::domain_error(what); |
| 23 | default: |
| 24 | throw ::std::system_error(errno, ::std::system_category(), what); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | } /* namespace gpiod */ |