| 1 | /* |
| 2 | * Distributed under the Boost Software License, Version 1.0. |
| 3 | * (See accompanying file LICENSE_1_0.txt or copy at |
| 4 | * https://www.boost.org/LICENSE_1_0.txt) |
| 5 | * |
| 6 | * Copyright (c) 2023 Andrey Semashev |
| 7 | */ |
| 8 | /*! |
| 9 | * \file scope/fd_resource_traits.hpp |
| 10 | * |
| 11 | * This header contains definition of \c unique_resource traits |
| 12 | * for compatibility with POSIX-like file descriptors. |
| 13 | */ |
| 14 | |
| 15 | #ifndef BOOST_SCOPE_FD_RESOURCE_TRAITS_HPP_INCLUDED_ |
| 16 | #define BOOST_SCOPE_FD_RESOURCE_TRAITS_HPP_INCLUDED_ |
| 17 | |
| 18 | #include <boost/scope/detail/config.hpp> |
| 19 | #include <boost/scope/detail/header.hpp> |
| 20 | |
| 21 | #ifdef BOOST_HAS_PRAGMA_ONCE |
| 22 | #pragma once |
| 23 | #endif |
| 24 | |
| 25 | namespace boost { |
| 26 | namespace scope { |
| 27 | |
| 28 | //! POSIX-like file descriptor resource traits |
| 29 | struct fd_resource_traits |
| 30 | { |
| 31 | //! Creates a default fd value |
| 32 | static int make_default() noexcept |
| 33 | { |
| 34 | return -1; |
| 35 | } |
| 36 | |
| 37 | //! Tests if the fd is allocated (valid) |
| 38 | static bool is_allocated(int fd) noexcept |
| 39 | { |
| 40 | return fd >= 0; |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | } // namespace scope |
| 45 | } // namespace boost |
| 46 | |
| 47 | #include <boost/scope/detail/footer.hpp> |
| 48 | |
| 49 | #endif // BOOST_SCOPE_FD_RESOURCE_TRAITS_HPP_INCLUDED_ |
| 50 | |