From 731df11ffdbb35348ff17c49044b1cbb962c4651 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 16 Sep 2018 05:44:58 +0300 Subject: [PATCH] Add system_category_posix.hpp; remove BOOST_SYSTEM_WIN32 --- include/boost/system/detail/config.hpp | 6 - .../system/detail/system_category_posix.hpp | 132 ++++++++++++++++++ .../system/detail/system_category_win32.hpp | 13 +- include/boost/system/error_code.hpp | 11 +- 4 files changed, 145 insertions(+), 17 deletions(-) create mode 100644 include/boost/system/detail/system_category_posix.hpp diff --git a/include/boost/system/detail/config.hpp b/include/boost/system/detail/config.hpp index e0b193f..1ff28f4 100644 --- a/include/boost/system/detail/config.hpp +++ b/include/boost/system/detail/config.hpp @@ -65,10 +65,4 @@ #endif #endif -// BOOST_SYSTEM_WIN32 - -#if defined( _WIN32 ) || defined( __CYGWIN__ ) -# define BOOST_SYSTEM_WIN32 -#endif - #endif // BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED diff --git a/include/boost/system/detail/system_category_posix.hpp b/include/boost/system/detail/system_category_posix.hpp new file mode 100644 index 0000000..9a40623 --- /dev/null +++ b/include/boost/system/detail/system_category_posix.hpp @@ -0,0 +1,132 @@ +// POSIX-specific implementation details of system_error_category +// +// Copyright 2018 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See library home page at http://www.boost.org/libs/system + +namespace boost +{ + +namespace system +{ + +namespace detail +{ + +inline bool is_generic_value( int ev ) BOOST_NOEXCEPT +{ + using namespace errc; + + static int const gen[] = + { + success, + address_family_not_supported, + address_in_use, + address_not_available, + already_connected, + argument_list_too_long, + argument_out_of_domain, + bad_address, + bad_file_descriptor, + bad_message, + broken_pipe, + connection_aborted, + connection_already_in_progress, + connection_refused, + connection_reset, + cross_device_link, + destination_address_required, + device_or_resource_busy, + directory_not_empty, + executable_format_error, + file_exists, + file_too_large, + filename_too_long, + function_not_supported, + host_unreachable, + identifier_removed, + illegal_byte_sequence, + inappropriate_io_control_operation, + interrupted, + invalid_argument, + invalid_seek, + io_error, + is_a_directory, + message_size, + network_down, + network_reset, + network_unreachable, + no_buffer_space, + no_child_process, + no_link, + no_lock_available, + no_message_available, + no_message, + no_protocol_option, + no_space_on_device, + no_stream_resources, + no_such_device_or_address, + no_such_device, + no_such_file_or_directory, + no_such_process, + not_a_directory, + not_a_socket, + not_a_stream, + not_connected, + not_enough_memory, + not_supported, + operation_canceled, + operation_in_progress, + operation_not_permitted, + operation_not_supported, + operation_would_block, + owner_dead, + permission_denied, + protocol_error, + protocol_not_supported, + read_only_file_system, + resource_deadlock_would_occur, + resource_unavailable_try_again, + result_out_of_range, + state_not_recoverable, + stream_timeout, + text_file_busy, + timed_out, + too_many_files_open_in_system, + too_many_files_open, + too_many_links, + too_many_symbolic_link_levels, + value_too_large, + wrong_protocol_type + }; + + int const n = sizeof( gen ) / sizeof( gen[0] ); + + for( int i = 0; i < n; ++i ) + { + if( ev == gen[ i ] ) return true; + } + + return false; +} + +inline error_condition system_category_default_error_condition_posix( int ev ) BOOST_NOEXCEPT +{ + if( is_generic_value( ev ) ) + { + return error_condition( ev, generic_category() ); + } + else + { + return error_condition( ev, system_category() ); + } +} + +} // namespace detail + +} // namespace system + +} // namespace boost diff --git a/include/boost/system/detail/system_category_win32.hpp b/include/boost/system/detail/system_category_win32.hpp index 075a1ce..66b8e1e 100644 --- a/include/boost/system/detail/system_category_win32.hpp +++ b/include/boost/system/detail/system_category_win32.hpp @@ -1,18 +1,17 @@ // Windows implementation of system_error_category - +// // Copyright Beman Dawes 2002, 2006 // Copyright (c) Microsoft Corporation 2014 // Copyright 2018 Peter Dimov - -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See library home page at http://www.boost.org/libs/system +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See library home page at http://www.boost.org/libs/system #include #include #include -#include // diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index 6cb09d6..8b21f88 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -10,6 +10,7 @@ // // See library home page at http://www.boost.org/libs/system +#include #include #include #include @@ -748,7 +749,7 @@ inline std::string generic_error_category::message( int ev ) const // system_error_category implementation -#if defined(BOOST_SYSTEM_WIN32) +#if defined(BOOST_WINDOWS_API) #include @@ -762,7 +763,9 @@ inline boost::system::error_condition boost::system::detail::system_error_catego return system_category_default_error_condition_win32( ev ); } -#else // #if defined(BOOST_SYSTEM_WIN32) +#else // #if defined(BOOST_WINDOWS_API) + +#include inline std::string boost::system::detail::system_error_category::message( int ev ) const { @@ -771,10 +774,10 @@ inline std::string boost::system::detail::system_error_category::message( int ev inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT { - return boost::system::error_condition( ev, generic_category() ); + return system_category_default_error_condition_posix( ev ); } -#endif // #if defined(BOOST_SYSTEM_WIN32) +#endif // #if defined(BOOST_WINDOWS_API) // interoperability with std::error_code, std::error_condition