diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b7165c0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,307 @@ +# Copyright 2016 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) + +language: cpp + +sudo: false + +python: "2.7" + +os: + - linux + - osx + +branches: + only: + - master + - develop + +env: + matrix: + - BOGUS_JOB=true + +matrix: + + exclude: + - env: BOGUS_JOB=true + + include: + - os: linux + env: TOOLSET=gcc COMPILER=g++ CXXSTD=c++03 + + - os: linux + env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=c++03 + addons: + apt: + packages: + - g++-4.7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=c++11 + addons: + apt: + packages: + - g++-4.7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=c++03 + addons: + apt: + packages: + - g++-4.8 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=c++11 + addons: + apt: + packages: + - g++-4.8 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=c++03 + addons: + apt: + packages: + - g++-4.9 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=c++11 + addons: + apt: + packages: + - g++-4.9 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++03 + addons: + apt: + packages: + - g++-5 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++11 + addons: + apt: + packages: + - g++-5 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++14 + addons: + apt: + packages: + - g++-5 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++03 + addons: + apt: + packages: + - g++-6 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++11 + addons: + apt: + packages: + - g++-6 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++14 + addons: + apt: + packages: + - g++-6 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++1z + addons: + apt: + packages: + - g++-6 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03 + + - os: linux + env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=c++03 + addons: + apt: + packages: + - clang-3.6 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.6 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=c++11 + addons: + apt: + packages: + - clang-3.6 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.6 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=c++03 + addons: + apt: + packages: + - clang-3.7 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.7 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=c++11 + addons: + apt: + packages: + - clang-3.7 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.7 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++03 + addons: + apt: + packages: + - clang-3.8 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++11 + addons: + apt: + packages: + - clang-3.8 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++14 + addons: + apt: + packages: + - clang-3.8 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++1z + addons: + apt: + packages: + - clang-3.8 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++03 + addons: + apt: + packages: + - clang-3.9 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.9 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++11 + addons: + apt: + packages: + - clang-3.9 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.9 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++14 + addons: + apt: + packages: + - clang-3.9 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.9 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++1z + addons: + apt: + packages: + - clang-3.9 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.9 + + - os: osx + env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03 + + - os: osx + env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11 + + - os: osx + env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++14 + + - os: osx + env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++1z + +install: + - cd .. + - git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root + - cd boost-root + - git submodule update --init tools/build + - git submodule update --init libs/config + - git submodule update --init tools/boostdep + - cp -r $TRAVIS_BUILD_DIR/* libs/system + - python tools/boostdep/depinst/depinst.py system + - ./bootstrap.sh + - ./b2 headers + +script: + - |- + echo "using $TOOLSET : : $COMPILER : -std=$CXXSTD ;" > ~/user-config.jam + - ./b2 libs/system/test toolset=$TOOLSET + +notifications: + email: + on_success: always diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..829bc5a --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,69 @@ +# Copyright 2016, 2017 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) + +version: 1.0.{build}-{branch} + +shallow_clone: true + +branches: + only: + - master + - develop + +environment: + matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + TOOLSET: msvc-9.0 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + TOOLSET: msvc-10.0 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + TOOLSET: msvc-11.0 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + TOOLSET: msvc-12.0 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ADDPATH: C:\cygwin\bin; + TOOLSET: gcc + CXXFLAGS: cxxflags=-std=c++03 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ADDPATH: C:\cygwin\bin; + TOOLSET: gcc + CXXFLAGS: cxxflags=-std=c++11 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ADDPATH: C:\mingw\bin; + TOOLSET: gcc + CXXFLAGS: cxxflags=-std=c++03 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ADDPATH: C:\mingw\bin; + TOOLSET: gcc + CXXFLAGS: cxxflags=-std=c++11 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin; + TOOLSET: gcc + CXXFLAGS: cxxflags=-std=c++03 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin; + TOOLSET: gcc + CXXFLAGS: cxxflags=-std=c++11 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + TOOLSET: msvc-14.0 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + TOOLSET: msvc-14.1 + +install: + - cd .. + - git clone -b %APPVEYOR_REPO_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root + - cd boost-root + - git submodule update --init tools/build + - git submodule update --init libs/config + - git submodule update --init tools/boostdep + - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\system + - python tools/boostdep/depinst/depinst.py system + - cmd /c bootstrap + - b2 headers + +build: off + +test_script: + - PATH=%ADDPATH%%PATH% + - b2 libs/system/test toolset=%TOOLSET% %CXXFLAGS% diff --git a/include/boost/system/detail/error_code.ipp b/include/boost/system/detail/error_code.ipp index 71c60f6..51ba3f4 100644 --- a/include/boost/system/detail/error_code.ipp +++ b/include/boost/system/detail/error_code.ipp @@ -1,4 +1,4 @@ -// error_code support implementation file ----------------------------------// +// error_code support implementation file --------------------------------------------// // Copyright Beman Dawes 2002, 2006 // Copyright (c) Microsoft Corporation 2014 @@ -7,7 +7,7 @@ // See library home page at http://www.boost.org/libs/system -//----------------------------------------------------------------------------// +//--------------------------------------------------------------------------------------// #include @@ -21,7 +21,9 @@ #include // for strerror/strerror_r # if defined( BOOST_WINDOWS_API ) -# include +# include +# include +# include # if !BOOST_PLAT_WINDOWS_RUNTIME # include # endif @@ -30,7 +32,7 @@ # endif # endif -//----------------------------------------------------------------------------// +//--------------------------------------------------------------------------------------// namespace boost { namespace system @@ -39,7 +41,7 @@ namespace boost namespace { - // standard error categories ---------------------------------------------// + // standard error categories -------------------------------------------------------// class generic_error_category : public error_category { @@ -84,7 +86,8 @@ namespace // -- VMS doesn't provide strerror_r, but on this platform, strerror is // thread safe. # if defined(BOOST_WINDOWS_API) || defined(__hpux) || defined(__sun)\ - || (defined(__linux) && (!defined(__USE_XOPEN2K) || defined(BOOST_SYSTEM_USE_STRERROR)))\ + || (defined(__linux) && (!defined(__USE_XOPEN2K)\ + || defined(BOOST_SYSTEM_USE_STRERROR)))\ || (defined(__osf__) && !defined(_REENTRANT))\ || (defined(__INTEGRITY))\ || (defined(__vms))\ @@ -156,14 +159,15 @@ namespace # endif // else POSIX version of strerror_r # endif // else use strerror_r } - // system_error_category implementation --------------------------------// + // system_error_category implementation --------------------------------------------// const char * system_error_category::name() const BOOST_SYSTEM_NOEXCEPT { return "system"; } - error_condition system_error_category::default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT + error_condition system_error_category::default_error_condition( int ev ) const + BOOST_SYSTEM_NOEXCEPT { using namespace boost::system::errc; #if defined(__PGI) @@ -179,13 +183,19 @@ namespace if ( HRESULT_FACILITY( ev ) == FACILITY_WIN32 ) ev = HRESULT_CODE( ev ); # endif +# endif + +# if defined(BOOST_WINDOWS_API) + + using namespace boost::detail::winapi; // for error codes + # endif switch ( ev ) { case 0: return make_error_condition( success ); # if defined(BOOST_POSIX_API) - // POSIX-like O/S -> posix_errno decode table ---------------------------// + // POSIX-like O/S -> posix_errno decode table -------------------------------------// case E2BIG: return make_error_condition( argument_list_too_long ); case EACCES: return make_error_condition( permission_denied ); case EADDRINUSE: return make_error_condition( address_in_use ); @@ -279,80 +289,81 @@ namespace #else // Windows system -> posix_errno decode table ---------------------------// // see WinError.h comments for descriptions of errors - case ERROR_ACCESS_DENIED: return make_error_condition( permission_denied ); - case ERROR_ALREADY_EXISTS: return make_error_condition( file_exists ); - case ERROR_BAD_UNIT: return make_error_condition( no_such_device ); - case ERROR_BUFFER_OVERFLOW: return make_error_condition( filename_too_long ); - case ERROR_BUSY: return make_error_condition( device_or_resource_busy ); - case ERROR_BUSY_DRIVE: return make_error_condition( device_or_resource_busy ); - case ERROR_CANNOT_MAKE: return make_error_condition( permission_denied ); - case ERROR_CANTOPEN: return make_error_condition( io_error ); - case ERROR_CANTREAD: return make_error_condition( io_error ); - case ERROR_CANTWRITE: return make_error_condition( io_error ); - case ERROR_CURRENT_DIRECTORY: return make_error_condition( permission_denied ); - case ERROR_DEV_NOT_EXIST: return make_error_condition( no_such_device ); - case ERROR_DEVICE_IN_USE: return make_error_condition( device_or_resource_busy ); - case ERROR_DIR_NOT_EMPTY: return make_error_condition( directory_not_empty ); - case ERROR_DIRECTORY: return make_error_condition( invalid_argument ); // WinError.h: "The directory name is invalid" - case ERROR_DISK_FULL: return make_error_condition( no_space_on_device ); - case ERROR_FILE_EXISTS: return make_error_condition( file_exists ); - case ERROR_FILE_NOT_FOUND: return make_error_condition( no_such_file_or_directory ); - case ERROR_HANDLE_DISK_FULL: return make_error_condition( no_space_on_device ); - case ERROR_INVALID_ACCESS: return make_error_condition( permission_denied ); - case ERROR_INVALID_DRIVE: return make_error_condition( no_such_device ); - case ERROR_INVALID_FUNCTION: return make_error_condition( function_not_supported ); - case ERROR_INVALID_HANDLE: return make_error_condition( invalid_argument ); - case ERROR_INVALID_NAME: return make_error_condition( invalid_argument ); - case ERROR_LOCK_VIOLATION: return make_error_condition( no_lock_available ); - case ERROR_LOCKED: return make_error_condition( no_lock_available ); - case ERROR_NEGATIVE_SEEK: return make_error_condition( invalid_argument ); - case ERROR_NOACCESS: return make_error_condition( permission_denied ); - case ERROR_NOT_ENOUGH_MEMORY: return make_error_condition( not_enough_memory ); - case ERROR_NOT_READY: return make_error_condition( resource_unavailable_try_again ); - case ERROR_NOT_SAME_DEVICE: return make_error_condition( cross_device_link ); - case ERROR_OPEN_FAILED: return make_error_condition( io_error ); - case ERROR_OPEN_FILES: return make_error_condition( device_or_resource_busy ); - case ERROR_OPERATION_ABORTED: return make_error_condition( operation_canceled ); - case ERROR_OUTOFMEMORY: return make_error_condition( not_enough_memory ); - case ERROR_PATH_NOT_FOUND: return make_error_condition( no_such_file_or_directory ); - case ERROR_READ_FAULT: return make_error_condition( io_error ); - case ERROR_RETRY: return make_error_condition( resource_unavailable_try_again ); - case ERROR_SEEK: return make_error_condition( io_error ); - case ERROR_SHARING_VIOLATION: return make_error_condition( permission_denied ); - case ERROR_TOO_MANY_OPEN_FILES: return make_error_condition( too_many_files_open ); - case ERROR_WRITE_FAULT: return make_error_condition( io_error ); - case ERROR_WRITE_PROTECT: return make_error_condition( permission_denied ); - case WSAEACCES: return make_error_condition( permission_denied ); - case WSAEADDRINUSE: return make_error_condition( address_in_use ); - case WSAEADDRNOTAVAIL: return make_error_condition( address_not_available ); - case WSAEAFNOSUPPORT: return make_error_condition( address_family_not_supported ); - case WSAEALREADY: return make_error_condition( connection_already_in_progress ); - case WSAEBADF: return make_error_condition( bad_file_descriptor ); - case WSAECONNABORTED: return make_error_condition( connection_aborted ); - case WSAECONNREFUSED: return make_error_condition( connection_refused ); - case WSAECONNRESET: return make_error_condition( connection_reset ); - case WSAEDESTADDRREQ: return make_error_condition( destination_address_required ); - case WSAEFAULT: return make_error_condition( bad_address ); - case WSAEHOSTUNREACH: return make_error_condition( host_unreachable ); - case WSAEINPROGRESS: return make_error_condition( operation_in_progress ); - case WSAEINTR: return make_error_condition( interrupted ); - case WSAEINVAL: return make_error_condition( invalid_argument ); - case WSAEISCONN: return make_error_condition( already_connected ); - case WSAEMFILE: return make_error_condition( too_many_files_open ); - case WSAEMSGSIZE: return make_error_condition( message_size ); - case WSAENAMETOOLONG: return make_error_condition( filename_too_long ); - case WSAENETDOWN: return make_error_condition( network_down ); - case WSAENETRESET: return make_error_condition( network_reset ); - case WSAENETUNREACH: return make_error_condition( network_unreachable ); - case WSAENOBUFS: return make_error_condition( no_buffer_space ); - case WSAENOPROTOOPT: return make_error_condition( no_protocol_option ); - case WSAENOTCONN: return make_error_condition( not_connected ); - case WSAENOTSOCK: return make_error_condition( not_a_socket ); - case WSAEOPNOTSUPP: return make_error_condition( operation_not_supported ); - case WSAEPROTONOSUPPORT: return make_error_condition( protocol_not_supported ); - case WSAEPROTOTYPE: return make_error_condition( wrong_protocol_type ); - case WSAETIMEDOUT: return make_error_condition( timed_out ); - case WSAEWOULDBLOCK: return make_error_condition( operation_would_block ); + case ERROR_ACCESS_DENIED_: return make_error_condition( permission_denied ); + case ERROR_ALREADY_EXISTS_: return make_error_condition( file_exists ); + case ERROR_BAD_UNIT_: return make_error_condition( no_such_device ); + case ERROR_BUFFER_OVERFLOW_: return make_error_condition( filename_too_long ); + case ERROR_BUSY_: return make_error_condition( device_or_resource_busy ); + case ERROR_BUSY_DRIVE_: return make_error_condition( device_or_resource_busy ); + case ERROR_CANNOT_MAKE_: return make_error_condition( permission_denied ); + case ERROR_CANTOPEN_: return make_error_condition( io_error ); + case ERROR_CANTREAD_: return make_error_condition( io_error ); + case ERROR_CANTWRITE_: return make_error_condition( io_error ); + case ERROR_CURRENT_DIRECTORY_: return make_error_condition( permission_denied ); + case ERROR_DEV_NOT_EXIST_: return make_error_condition( no_such_device ); + case ERROR_DEVICE_IN_USE_: return make_error_condition( device_or_resource_busy ); + case ERROR_DIR_NOT_EMPTY_: return make_error_condition( directory_not_empty ); + case ERROR_DIRECTORY_: return make_error_condition( invalid_argument );\ + // WinError.h: "The directory name is invalid" + case ERROR_DISK_FULL_: return make_error_condition( no_space_on_device ); + case ERROR_FILE_EXISTS_: return make_error_condition( file_exists ); + case ERROR_FILE_NOT_FOUND_: return make_error_condition( no_such_file_or_directory ); + case ERROR_HANDLE_DISK_FULL_: return make_error_condition( no_space_on_device ); + case ERROR_INVALID_ACCESS_: return make_error_condition( permission_denied ); + case ERROR_INVALID_DRIVE_: return make_error_condition( no_such_device ); + case ERROR_INVALID_FUNCTION_: return make_error_condition( function_not_supported ); + case ERROR_INVALID_HANDLE_: return make_error_condition( invalid_argument ); + case ERROR_INVALID_NAME_: return make_error_condition( invalid_argument ); + case ERROR_LOCK_VIOLATION_: return make_error_condition( no_lock_available ); + case ERROR_LOCKED_: return make_error_condition( no_lock_available ); + case ERROR_NEGATIVE_SEEK_: return make_error_condition( invalid_argument ); + case ERROR_NOACCESS_: return make_error_condition( permission_denied ); + case ERROR_NOT_ENOUGH_MEMORY_: return make_error_condition( not_enough_memory ); + case ERROR_NOT_READY_: return make_error_condition( resource_unavailable_try_again ); + case ERROR_NOT_SAME_DEVICE_: return make_error_condition( cross_device_link ); + case ERROR_OPEN_FAILED_: return make_error_condition( io_error ); + case ERROR_OPEN_FILES_: return make_error_condition( device_or_resource_busy ); + case ERROR_OPERATION_ABORTED_: return make_error_condition( operation_canceled ); + case ERROR_OUTOFMEMORY_: return make_error_condition( not_enough_memory ); + case ERROR_PATH_NOT_FOUND_: return make_error_condition( no_such_file_or_directory ); + case ERROR_READ_FAULT_: return make_error_condition( io_error ); + case ERROR_RETRY_: return make_error_condition( resource_unavailable_try_again ); + case ERROR_SEEK_: return make_error_condition( io_error ); + case ERROR_SHARING_VIOLATION_: return make_error_condition( permission_denied ); + case ERROR_TOO_MANY_OPEN_FILES_: return make_error_condition( too_many_files_open ); + case ERROR_WRITE_FAULT_: return make_error_condition( io_error ); + case ERROR_WRITE_PROTECT_: return make_error_condition( permission_denied ); + case WSAEACCES_: return make_error_condition( permission_denied ); + case WSAEADDRINUSE_: return make_error_condition( address_in_use ); + case WSAEADDRNOTAVAIL_: return make_error_condition( address_not_available ); + case WSAEAFNOSUPPORT_: return make_error_condition( address_family_not_supported ); + case WSAEALREADY_: return make_error_condition( connection_already_in_progress ); + case WSAEBADF_: return make_error_condition( bad_file_descriptor ); + case WSAECONNABORTED_: return make_error_condition( connection_aborted ); + case WSAECONNREFUSED_: return make_error_condition( connection_refused ); + case WSAECONNRESET_: return make_error_condition( connection_reset ); + case WSAEDESTADDRREQ_: return make_error_condition( destination_address_required ); + case WSAEFAULT_: return make_error_condition( bad_address ); + case WSAEHOSTUNREACH_: return make_error_condition( host_unreachable ); + case WSAEINPROGRESS_: return make_error_condition( operation_in_progress ); + case WSAEINTR_: return make_error_condition( interrupted ); + case WSAEINVAL_: return make_error_condition( invalid_argument ); + case WSAEISCONN_: return make_error_condition( already_connected ); + case WSAEMFILE_: return make_error_condition( too_many_files_open ); + case WSAEMSGSIZE_: return make_error_condition( message_size ); + case WSAENAMETOOLONG_: return make_error_condition( filename_too_long ); + case WSAENETDOWN_: return make_error_condition( network_down ); + case WSAENETRESET_: return make_error_condition( network_reset ); + case WSAENETUNREACH_: return make_error_condition( network_unreachable ); + case WSAENOBUFS_: return make_error_condition( no_buffer_space ); + case WSAENOPROTOOPT_: return make_error_condition( no_protocol_option ); + case WSAENOTCONN_: return make_error_condition( not_connected ); + case WSAENOTSOCK_: return make_error_condition( not_a_socket ); + case WSAEOPNOTSUPP_: return make_error_condition( operation_not_supported ); + case WSAEPROTONOSUPPORT_: return make_error_condition( protocol_not_supported ); + case WSAEPROTOTYPE_: return make_error_condition( wrong_protocol_type ); + case WSAETIMEDOUT_: return make_error_condition( timed_out ); + case WSAEWOULDBLOCK_: return make_error_condition( operation_would_block ); #endif default: return error_condition( ev, system_category() ); } @@ -372,12 +383,13 @@ namespace std::wstring buf(128, wchar_t()); for (;;) { - DWORD retval = ::FormatMessageW( - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, + boost::detail::winapi::DWORD_ retval = boost::detail::winapi::FormatMessageW( + boost::detail::winapi::FORMAT_MESSAGE_FROM_SYSTEM_ | + boost::detail::winapi::FORMAT_MESSAGE_IGNORE_INSERTS_, NULL, ev, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + boost::detail::winapi::MAKELANGID_(boost::detail::winapi::LANG_NEUTRAL_, + boost::detail::winapi::SUBLANG_DEFAULT_), // Default language &buf[0], buf.size(), NULL @@ -388,7 +400,8 @@ namespace buf.resize(retval); break; } - else if ( ::GetLastError() != ERROR_INSUFFICIENT_BUFFER ) + else if (boost::detail::winapi::GetLastError() != + boost::detail::winapi::ERROR_INSUFFICIENT_BUFFER_) { return std::string("Unknown error"); } @@ -399,23 +412,26 @@ namespace } int num_chars = (buf.size() + 1) * 2; - LPSTR narrow_buffer = (LPSTR)_alloca( num_chars ); - if (::WideCharToMultiByte(CP_ACP, 0, buf.c_str(), -1, narrow_buffer, num_chars, NULL, NULL) == 0) + boost::detail::winapi::LPSTR_ narrow_buffer = + (boost::detail::winapi::LPSTR_)_alloca(num_chars); + if (boost::detail::winapi::WideCharToMultiByte(boost::detail::winapi::CP_ACP_, 0, + buf.c_str(), -1, narrow_buffer, num_chars, NULL, NULL) == 0) { return std::string("Unknown error"); } std::string str( narrow_buffer ); #else - LPVOID lpMsgBuf = 0; - DWORD retval = ::FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, + boost::detail::winapi::LPVOID_ lpMsgBuf = 0; + boost::detail::winapi::DWORD_ retval = boost::detail::winapi::FormatMessageA( + boost::detail::winapi::FORMAT_MESSAGE_ALLOCATE_BUFFER_ | + boost::detail::winapi::FORMAT_MESSAGE_FROM_SYSTEM_ | + boost::detail::winapi::FORMAT_MESSAGE_IGNORE_INSERTS_, NULL, ev, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPSTR) &lpMsgBuf, + boost::detail::winapi::MAKELANGID_(boost::detail::winapi::LANG_NEUTRAL_, + boost::detail::winapi::SUBLANG_DEFAULT_), // Default language + (boost::detail::winapi::LPSTR_) &lpMsgBuf, 0, NULL ); @@ -423,7 +439,7 @@ namespace if (retval == 0) return std::string("Unknown error"); - std::string str( static_cast(lpMsgBuf) ); + std::string str(static_cast(lpMsgBuf)); # endif while ( str.size() && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') ) diff --git a/include/boost/system/detail/local_free_on_destruction.hpp b/include/boost/system/detail/local_free_on_destruction.hpp index 110024f..25f879b 100644 --- a/include/boost/system/detail/local_free_on_destruction.hpp +++ b/include/boost/system/detail/local_free_on_destruction.hpp @@ -12,6 +12,8 @@ #ifndef BOOST_SYSTEM_LOCAL_FREE_ON_EXIT_HPP #define BOOST_SYSTEM_LOCAL_FREE_ON_EXIT_HPP +#include + namespace boost { namespace system { namespace detail { @@ -24,7 +26,7 @@ public: ~local_free_on_destruction() { - ::LocalFree(p_); + boost::detail::winapi::LocalFree(p_); } private: diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index b6ff6e4..1ddb471 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -1,4 +1,4 @@ -// boost/system/error_code.hpp ---------------------------------------------// +// boost/system/error_code.hpp -------------------------------------------------------// // Copyright Beman Dawes 2006, 2007 // Copyright Christoper Kohlhoff 2007 @@ -28,6 +28,10 @@ # error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined #endif +#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR +#include +#endif + #include // must be the last #include #ifndef BOOST_SYSTEM_NOEXCEPT @@ -43,7 +47,7 @@ namespace boost class error_condition; // portable generic values defined below, but ultimately // based on the POSIX standard - // "Concept" helpers ---------------------------------------------------// + // "Concept" helpers -------------------------------------------------------------// template< class T > struct is_error_code_enum { static const bool value = false; }; @@ -51,7 +55,7 @@ namespace boost template< class T > struct is_error_condition_enum { static const bool value = false; }; - // generic error_conditions --------------------------------------------// + // generic error_conditions ------------------------------------------------------// namespace errc { @@ -149,9 +153,9 @@ namespace boost { static const bool value = true; }; - // ----------------------------------------------------------------------// + // --------------------------------------------------------------------------------// - // Operating system specific interfaces --------------------------------// + // Operating system specific interfaces ------------------------------------------// // The interface is divided into general and system-specific portions to @@ -179,52 +183,109 @@ namespace boost // These headers are effectively empty for compiles on operating systems // where they are not applicable. - // ----------------------------------------------------------------------// + // --------------------------------------------------------------------------------// - // class error_category ------------------------------------------------// + class error_category; - class error_category : public noncopyable - { - public: - virtual ~error_category(){} + // predefined error categories ---------------------------------------------------// - virtual const char * name() const BOOST_SYSTEM_NOEXCEPT = 0; - virtual std::string message( int ev ) const = 0; - inline virtual error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT; - inline virtual bool equivalent( int code, - const error_condition & condition ) const BOOST_SYSTEM_NOEXCEPT; - inline virtual bool equivalent( const error_code & code, - int condition ) const BOOST_SYSTEM_NOEXCEPT; - - bool operator==(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT { return this == &rhs; } - bool operator!=(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT { return this != &rhs; } - bool operator<( const error_category & rhs ) const BOOST_SYSTEM_NOEXCEPT - { - return std::less()( this, &rhs ); - } - }; - - // predefined error categories -----------------------------------------// - -# ifdef BOOST_ERROR_CODE_HEADER_ONLY +#ifdef BOOST_ERROR_CODE_HEADER_ONLY inline const error_category & system_category() BOOST_SYSTEM_NOEXCEPT; inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT; #else BOOST_SYSTEM_DECL const error_category & system_category() BOOST_SYSTEM_NOEXCEPT; BOOST_SYSTEM_DECL const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT; #endif - // deprecated synonyms --------------------------------------------------// + // deprecated synonyms ------------------------------------------------------------// -# ifndef BOOST_SYSTEM_NO_DEPRECATED +#ifndef BOOST_SYSTEM_NO_DEPRECATED inline const error_category & get_system_category() { return system_category(); } inline const error_category & get_generic_category() { return generic_category(); } inline const error_category & get_posix_category() { return generic_category(); } - static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED = generic_category(); - static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED = generic_category(); - static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED = system_category(); -# endif + static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED + = generic_category(); + static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED + = generic_category(); + static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED + = system_category(); +#endif - // class error_condition -----------------------------------------------// + // class error_category ------------------------------------------------// + + class error_category : public noncopyable + { +#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR + + private: + + class std_category: public std::error_category + { + private: + + boost::system::error_category const * pc_; + + public: + + explicit std_category( boost::system::error_category const * pc ): pc_( pc ) + { + } + + virtual const char * name() const BOOST_NOEXCEPT + { + return pc_->name(); + } + + virtual std::string message( int ev ) const + { + return pc_->message( ev ); + } + + virtual std::error_condition default_error_condition( int ev ) const + BOOST_NOEXCEPT; + virtual bool equivalent( int code, const std::error_condition & condition ) const + BOOST_NOEXCEPT; + virtual bool equivalent( const std::error_code & code, int condition ) const + BOOST_NOEXCEPT; + }; + + std_category std_cat_; + + public: + + error_category() BOOST_SYSTEM_NOEXCEPT: std_cat_( this ) {} + + operator std::error_category const & () const BOOST_SYSTEM_NOEXCEPT + { + // do not map generic to std::generic on purpose; occasionally, + // there are two std::generic categories in a program, which leads + // to error codes/conditions mysteriously not being equal to themselves + return std_cat_; + } + +#endif + + public: + virtual ~error_category(){} + + virtual const char * name() const BOOST_SYSTEM_NOEXCEPT = 0; + virtual std::string message( int ev ) const = 0; + inline virtual error_condition default_error_condition( int ev ) const + BOOST_SYSTEM_NOEXCEPT; + inline virtual bool equivalent( int code, + const error_condition & condition ) const + BOOST_SYSTEM_NOEXCEPT; + inline virtual bool equivalent( const error_code & code, + int condition ) const BOOST_SYSTEM_NOEXCEPT; + + bool operator==(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT + { return this == &rhs; } + bool operator!=(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT + { return this != &rhs; } + bool operator<( const error_category & rhs ) const BOOST_SYSTEM_NOEXCEPT + { return std::less()( this, &rhs ); } + }; + + // class error_condition ---------------------------------------------------------// // error_conditions are portable, error_codes are system or library specific @@ -234,11 +295,13 @@ namespace boost // constructors: error_condition() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&generic_category()) {} - error_condition( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT : m_val(val), m_cat(&cat) {} + error_condition( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT + : m_val(val), m_cat(&cat) {} template error_condition(ErrorConditionEnum e, - typename boost::enable_if >::type* = 0) BOOST_SYSTEM_NOEXCEPT + typename boost::enable_if >::type* + = 0) BOOST_SYSTEM_NOEXCEPT { *this = make_error_condition(e); } @@ -252,7 +315,8 @@ namespace boost } template - typename boost::enable_if, error_condition>::type & + typename boost::enable_if, + error_condition>::type & operator=( ErrorConditionEnum val ) BOOST_SYSTEM_NOEXCEPT { *this = make_error_condition(val); @@ -301,13 +365,22 @@ namespace boost || (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val); } +#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR + + operator std::error_condition () const BOOST_SYSTEM_NOEXCEPT + { + return std::error_condition( value(), category() ); + } + +#endif + private: int m_val; const error_category * m_cat; }; - // class error_code ----------------------------------------------------// + // class error_code --------------------------------------------------------------// // We want error_code to be a value type that can be copied without slicing // and without requiring heap allocation, but we also want it to have @@ -321,11 +394,13 @@ namespace boost // constructors: error_code() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&system_category()) {} - error_code( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT : m_val(val), m_cat(&cat) {} + error_code( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT + : m_val(val), m_cat(&cat) {} template error_code(ErrorCodeEnum e, - typename boost::enable_if >::type* = 0) BOOST_SYSTEM_NOEXCEPT + typename boost::enable_if >::type* = 0) + BOOST_SYSTEM_NOEXCEPT { *this = make_error_code(e); } @@ -354,7 +429,8 @@ namespace boost // observers: int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; } const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; } - error_condition default_error_condition() const BOOST_SYSTEM_NOEXCEPT { return m_cat->default_error_condition(value()); } + error_condition default_error_condition() const BOOST_SYSTEM_NOEXCEPT + { return m_cat->default_error_condition(value()); } std::string message() const { return m_cat->message(value()); } typedef void (*unspecified_bool_type)(); @@ -388,6 +464,15 @@ namespace boost || (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val); } +#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR + + operator std::error_code () const BOOST_SYSTEM_NOEXCEPT + { + return std::error_code( value(), category() ); + } + +#endif + private: int m_val; const error_category * m_cat; @@ -475,7 +560,7 @@ namespace boost + reinterpret_cast(&ec.category()); } - // make_* functions for errc::errc_t -----------------------------// + // make_* functions for errc::errc_t ---------------------------------------------// namespace errc { @@ -488,9 +573,10 @@ namespace boost { return error_condition( e, generic_category() ); } } - // error_category default implementation -------------------------------// + // error_category default implementation -----------------------------------------// - error_condition error_category::default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT + error_condition error_category::default_error_condition( int ev ) const + BOOST_SYSTEM_NOEXCEPT { return error_condition( ev, *this ); } @@ -507,6 +593,80 @@ namespace boost return *this == code.category() && code.value() == condition; } +#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR + + inline std::error_condition error_category::std_category::default_error_condition( + int ev ) const BOOST_NOEXCEPT + { + return pc_->default_error_condition( ev ); + } + + inline bool error_category::std_category::equivalent( int code, + const std::error_condition & condition ) const BOOST_NOEXCEPT + { + if( condition.category() == *this ) + { + boost::system::error_condition bn( condition.value(), *pc_ ); + return pc_->equivalent( code, bn ); + } + else if( condition.category() == std::generic_category() + || condition.category() == boost::system::generic_category() ) + { + boost::system::error_condition bn( condition.value(), + boost::system::generic_category() ); + + return pc_->equivalent( code, bn ); + } +#ifndef BOOST_NO_RTTI + else if( std_category const* pc2 = dynamic_cast< std_category const* >( + &condition.category() ) ) + { + boost::system::error_condition bn( condition.value(), *pc2->pc_ ); + return pc_->equivalent( code, bn ); + } +#endif + else + { + return default_error_condition( code ) == condition; + } + } + + inline bool error_category::std_category::equivalent( const std::error_code & code, + int condition ) const BOOST_NOEXCEPT + { + if( code.category() == *this ) + { + boost::system::error_code bc( code.value(), *pc_ ); + return pc_->equivalent( bc, condition ); + } + else if( code.category() == std::generic_category() + || code.category() == boost::system::generic_category() ) + { + boost::system::error_code bc( code.value(), + boost::system::generic_category() ); + + return pc_->equivalent( bc, condition ); + } +#ifndef BOOST_NO_RTTI + else if( std_category const* pc2 = dynamic_cast< std_category const* >( + &code.category() ) ) + { + boost::system::error_code bc( code.value(), *pc2->pc_ ); + return pc_->equivalent( bc, condition ); + } +#endif + else if( *pc_ == boost::system::generic_category() ) + { + return std::generic_category().equivalent( code, condition ); + } + else + { + return false; + } + } + +#endif + } // namespace system } // namespace boost @@ -517,5 +677,3 @@ namespace boost # endif #endif // BOOST_SYSTEM_ERROR_CODE_HPP - - diff --git a/include/boost/system/system_error.hpp b/include/boost/system/system_error.hpp index d98b4bc..c5e7e40 100644 --- a/include/boost/system/system_error.hpp +++ b/include/boost/system/system_error.hpp @@ -44,10 +44,10 @@ namespace boost const char * what_arg ) : std::runtime_error(what_arg), m_error_code(ev,ecat) {} - virtual ~system_error() throw() {} + virtual ~system_error() BOOST_NOEXCEPT_OR_NOTHROW {} - const error_code & code() const throw() { return m_error_code; } - const char * what() const throw(); + const error_code & code() const BOOST_NOEXCEPT_OR_NOTHROW { return m_error_code; } + const char * what() const BOOST_NOEXCEPT_OR_NOTHROW; private: error_code m_error_code; @@ -56,7 +56,7 @@ namespace boost // implementation ------------------------------------------------------// - inline const char * system_error::what() const throw() + inline const char * system_error::what() const BOOST_NOEXCEPT_OR_NOTHROW // see http://www.boost.org/more/error_handling.html for lazy build rationale { if ( m_what.empty() ) diff --git a/include/boost/system/windows_error.hpp b/include/boost/system/windows_error.hpp index 38d6284..0fb7ea6 100644 --- a/include/boost/system/windows_error.hpp +++ b/include/boost/system/windows_error.hpp @@ -19,14 +19,16 @@ #include -// Neither MinGW or Cygwin versions of winerror.h work if used alone, so on -// either of those platforms include the full windows.h +//// Neither MinGW or Cygwin versions of winerror.h work if used alone, so on +//// either of those platforms include the full windows.h +// +//#if defined(__MINGW32__) || defined(__CYGWIN__) +//#include +//#else +//#include +//#endif -#if defined(__MINGW32__) || defined(__CYGWIN__) -#include -#else -#include -#endif +#include namespace boost { @@ -45,59 +47,59 @@ namespace boost { success = 0, // These names and values are based on Windows winerror.h - invalid_function = ERROR_INVALID_FUNCTION, - file_not_found = ERROR_FILE_NOT_FOUND, - path_not_found = ERROR_PATH_NOT_FOUND, - too_many_open_files = ERROR_TOO_MANY_OPEN_FILES, - access_denied = ERROR_ACCESS_DENIED, - invalid_handle = ERROR_INVALID_HANDLE, - arena_trashed = ERROR_ARENA_TRASHED, - not_enough_memory = ERROR_NOT_ENOUGH_MEMORY, - invalid_block = ERROR_INVALID_BLOCK, - bad_environment = ERROR_BAD_ENVIRONMENT, - bad_format = ERROR_BAD_FORMAT, - invalid_access = ERROR_INVALID_ACCESS, - outofmemory = ERROR_OUTOFMEMORY, - invalid_drive = ERROR_INVALID_DRIVE, - current_directory = ERROR_CURRENT_DIRECTORY, - not_same_device = ERROR_NOT_SAME_DEVICE, - no_more_files = ERROR_NO_MORE_FILES, - write_protect = ERROR_WRITE_PROTECT, - bad_unit = ERROR_BAD_UNIT, - not_ready = ERROR_NOT_READY, - bad_command = ERROR_BAD_COMMAND, - crc = ERROR_CRC, - bad_length = ERROR_BAD_LENGTH, - seek = ERROR_SEEK, - not_dos_disk = ERROR_NOT_DOS_DISK, - sector_not_found = ERROR_SECTOR_NOT_FOUND, - out_of_paper = ERROR_OUT_OF_PAPER, - write_fault = ERROR_WRITE_FAULT, - read_fault = ERROR_READ_FAULT, - gen_failure = ERROR_GEN_FAILURE, - sharing_violation = ERROR_SHARING_VIOLATION, - lock_violation = ERROR_LOCK_VIOLATION, - wrong_disk = ERROR_WRONG_DISK, - sharing_buffer_exceeded = ERROR_SHARING_BUFFER_EXCEEDED, - handle_eof = ERROR_HANDLE_EOF, - handle_disk_full= ERROR_HANDLE_DISK_FULL, - rem_not_list = ERROR_REM_NOT_LIST, - dup_name = ERROR_DUP_NAME, - bad_net_path = ERROR_BAD_NETPATH, - network_busy = ERROR_NETWORK_BUSY, + invalid_function = boost::detail::winapi::ERROR_INVALID_FUNCTION_, + file_not_found = boost::detail::winapi::ERROR_FILE_NOT_FOUND_, + path_not_found = boost::detail::winapi::ERROR_PATH_NOT_FOUND_, + too_many_open_files = boost::detail::winapi::ERROR_TOO_MANY_OPEN_FILES_, + access_denied = boost::detail::winapi::ERROR_ACCESS_DENIED_, + invalid_handle = boost::detail::winapi::ERROR_INVALID_HANDLE_, + arena_trashed = boost::detail::winapi::ERROR_ARENA_TRASHED_, + not_enough_memory = boost::detail::winapi::ERROR_NOT_ENOUGH_MEMORY_, + invalid_block = boost::detail::winapi::ERROR_INVALID_BLOCK_, + bad_environment = boost::detail::winapi::ERROR_BAD_ENVIRONMENT_, + bad_format = boost::detail::winapi::ERROR_BAD_FORMAT_, + invalid_access = boost::detail::winapi::ERROR_INVALID_ACCESS_, + outofmemory = boost::detail::winapi::ERROR_OUTOFMEMORY_, + invalid_drive = boost::detail::winapi::ERROR_INVALID_DRIVE_, + current_directory = boost::detail::winapi::ERROR_CURRENT_DIRECTORY_, + not_same_device = boost::detail::winapi::ERROR_NOT_SAME_DEVICE_, + no_more_files = boost::detail::winapi::ERROR_NO_MORE_FILES_, + write_protect = boost::detail::winapi::ERROR_WRITE_PROTECT_, + bad_unit = boost::detail::winapi::ERROR_BAD_UNIT_, + not_ready = boost::detail::winapi::ERROR_NOT_READY_, + bad_command = boost::detail::winapi::ERROR_BAD_COMMAND_, + crc = boost::detail::winapi::ERROR_CRC_, + bad_length = boost::detail::winapi::ERROR_BAD_LENGTH_, + seek = boost::detail::winapi::ERROR_SEEK_, + not_dos_disk = boost::detail::winapi::ERROR_NOT_DOS_DISK_, + sector_not_found = boost::detail::winapi::ERROR_SECTOR_NOT_FOUND_, + out_of_paper = boost::detail::winapi::ERROR_OUT_OF_PAPER_, + write_fault = boost::detail::winapi::ERROR_WRITE_FAULT_, + read_fault = boost::detail::winapi::ERROR_READ_FAULT_, + gen_failure = boost::detail::winapi::ERROR_GEN_FAILURE_, + sharing_violation = boost::detail::winapi::ERROR_SHARING_VIOLATION_, + lock_violation = boost::detail::winapi::ERROR_LOCK_VIOLATION_, + wrong_disk = boost::detail::winapi::ERROR_WRONG_DISK_, + sharing_buffer_exceeded = boost::detail::winapi::ERROR_SHARING_BUFFER_EXCEEDED_, + handle_eof = boost::detail::winapi::ERROR_HANDLE_EOF_, + handle_disk_full= boost::detail::winapi::ERROR_HANDLE_DISK_FULL_, + rem_not_list = boost::detail::winapi::ERROR_REM_NOT_LIST_, + dup_name = boost::detail::winapi::ERROR_DUP_NAME_, + bad_net_path = boost::detail::winapi::ERROR_BAD_NETPATH_, + network_busy = boost::detail::winapi::ERROR_NETWORK_BUSY_, // ... - file_exists = ERROR_FILE_EXISTS, - cannot_make = ERROR_CANNOT_MAKE, + file_exists = boost::detail::winapi::ERROR_FILE_EXISTS_, + cannot_make = boost::detail::winapi::ERROR_CANNOT_MAKE_, // ... - broken_pipe = ERROR_BROKEN_PIPE, - open_failed = ERROR_OPEN_FAILED, - buffer_overflow = ERROR_BUFFER_OVERFLOW, - disk_full= ERROR_DISK_FULL, + broken_pipe = boost::detail::winapi::ERROR_BROKEN_PIPE_, + open_failed = boost::detail::winapi::ERROR_OPEN_FAILED_, + buffer_overflow = boost::detail::winapi::ERROR_BUFFER_OVERFLOW_, + disk_full= boost::detail::winapi::ERROR_DISK_FULL_, // ... - lock_failed = ERROR_LOCK_FAILED, - busy = ERROR_BUSY, - cancel_violation = ERROR_CANCEL_VIOLATION, - already_exists = ERROR_ALREADY_EXISTS + lock_failed = boost::detail::winapi::ERROR_LOCK_FAILED_, + busy = boost::detail::winapi::ERROR_BUSY_, + cancel_violation = boost::detail::winapi::ERROR_CANCEL_VIOLATION_, + already_exists = boost::detail::winapi::ERROR_ALREADY_EXISTS_ // ... // TODO: add more Windows errors diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 024cb88..d3ba574 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -7,6 +7,7 @@ # See library home page at http://www.boost.org/libs/system +import testing ; project : requirements @@ -55,4 +56,10 @@ project [ run config_test.cpp : : : always_show_run_output ] + [ run std_interop_test.cpp + : : : static + ] + [ run std_interop_test.cpp + : : : shared : std_interop_test_shared + ] ; diff --git a/test/error_code_test.cpp b/test/error_code_test.cpp index a9a928e..3cad994 100644 --- a/test/error_code_test.cpp +++ b/test/error_code_test.cpp @@ -30,14 +30,20 @@ // with a boost::system using directive increases use scenario coverage. using namespace boost::system; -# if defined( BOOST_WINDOWS_API ) -# include "winerror.h" -# define BOOST_ACCESS_ERROR_MACRO ERROR_ACCESS_DENIED -# elif defined( BOOST_POSIX_API ) -# define BOOST_ACCESS_ERROR_MACRO EACCES -# else -# error "Only supported for POSIX and Windows" -# endif +#if defined( BOOST_WINDOWS_API ) +// Neither MinGW or Cygwin versions of winerror.h work if used alone, so on +// either of those platforms include the full windows.h +# if defined(__MINGW32__) || defined(__CYGWIN__) +# include +# else +# include +# endif +# define BOOST_ACCESS_ERROR_MACRO ERROR_ACCESS_DENIED +#elif defined( BOOST_POSIX_API ) +# define BOOST_ACCESS_ERROR_MACRO EACCES +#else +# error "Only supported for POSIX and Windows" +#endif namespace { diff --git a/test/msvc/config_test/config_test.vcxproj b/test/msvc/config_test/config_test.vcxproj index 396f312..484ad8d 100644 --- a/test/msvc/config_test/config_test.vcxproj +++ b/test/msvc/config_test/config_test.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -19,13 +19,13 @@ Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode diff --git a/test/msvc/error_code_test/error_code_test.vcxproj b/test/msvc/error_code_test/error_code_test.vcxproj index 12c91cd..2edf1bf 100644 --- a/test/msvc/error_code_test/error_code_test.vcxproj +++ b/test/msvc/error_code_test/error_code_test.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -19,13 +19,13 @@ Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode diff --git a/test/msvc/header_only_error_code_test/header_only_error_code_test.vcxproj b/test/msvc/header_only_error_code_test/header_only_error_code_test.vcxproj new file mode 100644 index 0000000..2649e3a --- /dev/null +++ b/test/msvc/header_only_error_code_test/header_only_error_code_test.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7} + Win32Proj + header_only_error_code_test + 10.0.14393.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY + + + Console + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY + + + Console + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY + + + Console + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY + + + Console + true + true + + + + + + + + + \ No newline at end of file diff --git a/test/msvc/header_only_test/header_only_test.vcxproj b/test/msvc/header_only_test/header_only_test.vcxproj index 199b23e..5dd9e29 100644 --- a/test/msvc/header_only_test/header_only_test.vcxproj +++ b/test/msvc/header_only_test/header_only_test.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -19,13 +19,13 @@ Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode diff --git a/test/msvc/std_interop_test/std_interop_test.vcxproj b/test/msvc/std_interop_test/std_interop_test.vcxproj new file mode 100644 index 0000000..39fe49c --- /dev/null +++ b/test/msvc/std_interop_test/std_interop_test.vcxproj @@ -0,0 +1,156 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {47B0A041-1EB5-4842-BD17-BA0DCC5E0313} + Win32Proj + std_interop_test + 10.0.14393.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + + + + + + + + {419402d4-f990-4b05-a459-655e2dc33dc2} + + + + + + \ No newline at end of file diff --git a/test/msvc/system-dll/system-dll.vcxproj b/test/msvc/system-dll/system-dll.vcxproj index aca6f00..cd7174d 100644 --- a/test/msvc/system-dll/system-dll.vcxproj +++ b/test/msvc/system-dll/system-dll.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -19,13 +19,13 @@ DynamicLibrary true - v140 + v141 Unicode DynamicLibrary false - v140 + v141 true Unicode @@ -54,6 +54,7 @@ Level3 Disabled WIN32;_DEBUG;_WINDOWS;_USRDLL;SYSTEMDLL_EXPORTS;%(PreprocessorDefinitions) + stdcpplatest Windows diff --git a/test/msvc/system.sln b/test/msvc/system.sln index b544fb0..25b44db 100644 --- a/test/msvc/system.sln +++ b/test/msvc/system.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 2013 for Windows Desktop -VisualStudioVersion = 12.0.30626.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.6 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "system-dll", "system-dll\system-dll.vcxproj", "{419402D4-F990-4B05-A459-655E2DC33DC2}" EndProject @@ -11,28 +11,71 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "header_only_test", "header_ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "config_test", "config_test\config_test.vcxproj", "{E18C2B56-DCEC-438F-9C38-3C8B08B65247}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clang-system-dll", "clang-system-dll\clang-system-dll.vcxproj", "{30993F97-5E77-4B5A-B25F-B545C276077A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "std_interop_test", "std_interop_test\std_interop_test.vcxproj", "{47B0A041-1EB5-4842-BD17-BA0DCC5E0313}" + ProjectSection(ProjectDependencies) = postProject + {419402D4-F990-4B05-A459-655E2DC33DC2} = {419402D4-F990-4B05-A459-655E2DC33DC2} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "header_only_error_code_test", "header_only_error_code_test\header_only_error_code_test.vcxproj", "{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {419402D4-F990-4B05-A459-655E2DC33DC2}.Debug|Win32.ActiveCfg = Debug|Win32 {419402D4-F990-4B05-A459-655E2DC33DC2}.Debug|Win32.Build.0 = Debug|Win32 + {419402D4-F990-4B05-A459-655E2DC33DC2}.Debug|x64.ActiveCfg = Debug|Win32 {419402D4-F990-4B05-A459-655E2DC33DC2}.Release|Win32.ActiveCfg = Release|Win32 {419402D4-F990-4B05-A459-655E2DC33DC2}.Release|Win32.Build.0 = Release|Win32 + {419402D4-F990-4B05-A459-655E2DC33DC2}.Release|x64.ActiveCfg = Release|Win32 {E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Debug|Win32.ActiveCfg = Debug|Win32 {E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Debug|Win32.Build.0 = Debug|Win32 + {E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Debug|x64.ActiveCfg = Debug|Win32 {E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Release|Win32.ActiveCfg = Release|Win32 {E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Release|Win32.Build.0 = Release|Win32 + {E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Release|x64.ActiveCfg = Release|Win32 {3773451B-A618-4A26-A7F2-85554F4BD21B}.Debug|Win32.ActiveCfg = Debug|Win32 {3773451B-A618-4A26-A7F2-85554F4BD21B}.Debug|Win32.Build.0 = Debug|Win32 + {3773451B-A618-4A26-A7F2-85554F4BD21B}.Debug|x64.ActiveCfg = Debug|Win32 {3773451B-A618-4A26-A7F2-85554F4BD21B}.Release|Win32.ActiveCfg = Release|Win32 {3773451B-A618-4A26-A7F2-85554F4BD21B}.Release|Win32.Build.0 = Release|Win32 + {3773451B-A618-4A26-A7F2-85554F4BD21B}.Release|x64.ActiveCfg = Release|Win32 {E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Debug|Win32.ActiveCfg = Debug|Win32 {E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Debug|Win32.Build.0 = Debug|Win32 + {E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Debug|x64.ActiveCfg = Debug|Win32 {E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Release|Win32.ActiveCfg = Release|Win32 {E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Release|Win32.Build.0 = Release|Win32 + {E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Release|x64.ActiveCfg = Release|Win32 + {30993F97-5E77-4B5A-B25F-B545C276077A}.Debug|Win32.ActiveCfg = Debug|Win32 + {30993F97-5E77-4B5A-B25F-B545C276077A}.Debug|Win32.Build.0 = Debug|Win32 + {30993F97-5E77-4B5A-B25F-B545C276077A}.Debug|x64.ActiveCfg = Debug|x64 + {30993F97-5E77-4B5A-B25F-B545C276077A}.Debug|x64.Build.0 = Debug|x64 + {30993F97-5E77-4B5A-B25F-B545C276077A}.Release|Win32.ActiveCfg = Release|Win32 + {30993F97-5E77-4B5A-B25F-B545C276077A}.Release|Win32.Build.0 = Release|Win32 + {30993F97-5E77-4B5A-B25F-B545C276077A}.Release|x64.ActiveCfg = Release|x64 + {30993F97-5E77-4B5A-B25F-B545C276077A}.Release|x64.Build.0 = Release|x64 + {47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Debug|Win32.ActiveCfg = Debug|Win32 + {47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Debug|Win32.Build.0 = Debug|Win32 + {47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Debug|x64.ActiveCfg = Debug|x64 + {47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Debug|x64.Build.0 = Debug|x64 + {47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Release|Win32.ActiveCfg = Release|Win32 + {47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Release|Win32.Build.0 = Release|Win32 + {47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Release|x64.ActiveCfg = Release|x64 + {47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Release|x64.Build.0 = Release|x64 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|Win32.ActiveCfg = Debug|Win32 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|Win32.Build.0 = Debug|Win32 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|x64.ActiveCfg = Debug|x64 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|x64.Build.0 = Debug|x64 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|Win32.ActiveCfg = Release|Win32 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|Win32.Build.0 = Release|Win32 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|x64.ActiveCfg = Release|x64 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/std_interop_test.cpp b/test/std_interop_test.cpp new file mode 100644 index 0000000..5e52c50 --- /dev/null +++ b/test/std_interop_test.cpp @@ -0,0 +1,370 @@ + +// Copyright 2017 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 + +// Avoid spurious VC++ warnings +# define _CRT_SECURE_NO_WARNINGS + +#include +#include + +#if defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) + +int main() +{ + std::cout + << "The version of the C++ standard library being used does not" + " support header so interoperation will not be tested.\n"; +} + +#else + +#include +#include +#include +#include +#include +#include + +static void test_generic_category() +{ + boost::system::error_category const & bt = boost::system::generic_category(); + std::error_category const & st = bt; + + BOOST_TEST_CSTR_EQ( bt.name(), st.name() ); + + int ev = ENOENT; + + BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) ); + + { + boost::system::error_code bc( ev, bt ); + + BOOST_TEST_EQ( bc.value(), ev ); + BOOST_TEST_EQ( &bc.category(), &bt ); + + std::error_code sc( bc ); + + BOOST_TEST_EQ( sc.value(), ev ); + BOOST_TEST_EQ( &sc.category(), &st ); + } + + { + boost::system::error_condition bn = bt.default_error_condition( ev ); + + BOOST_TEST_EQ( bn.value(), ev ); + BOOST_TEST_EQ( &bn.category(), &bt ); + + BOOST_TEST( bt.equivalent( ev, bn ) ); + + std::error_condition sn( bn ); + + BOOST_TEST_EQ( sn.value(), ev ); + BOOST_TEST_EQ( &sn.category(), &st ); + + BOOST_TEST( st.equivalent( ev, sn ) ); + } +} + +static void test_system_category() +{ + boost::system::error_category const & bt = boost::system::system_category(); + std::error_category const & st = bt; + + BOOST_TEST_CSTR_EQ( bt.name(), st.name() ); + + { + int ev = 5; + BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) ); + + { + boost::system::error_code bc( ev, bt ); + + BOOST_TEST_EQ( bc.value(), ev ); + BOOST_TEST_EQ( &bc.category(), &bt ); + + std::error_code sc( bc ); + + BOOST_TEST_EQ( sc.value(), ev ); + BOOST_TEST_EQ( &sc.category(), &st ); + } + + { + boost::system::error_condition bn = bt.default_error_condition( ev ); + BOOST_TEST( bt.equivalent( ev, bn ) ); + + std::error_condition sn( bn ); + BOOST_TEST( st.equivalent( ev, sn ) ); + } + } + + { + int ev = 4; + BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) ); + + { + boost::system::error_code bc( ev, bt ); + + BOOST_TEST_EQ( bc.value(), ev ); + BOOST_TEST_EQ( &bc.category(), &bt ); + + std::error_code sc( bc ); + + BOOST_TEST_EQ( sc.value(), ev ); + BOOST_TEST_EQ( &sc.category(), &st ); + } + + { + boost::system::error_condition bn = bt.default_error_condition( ev ); + BOOST_TEST( bt.equivalent( ev, bn ) ); + + std::error_condition sn( bn ); + BOOST_TEST( st.equivalent( ev, sn ) ); + } + } +} + +// test_user_category + +class user_category_impl: public boost::system::error_category +{ +public: + + virtual const char * name() const BOOST_NOEXCEPT + { + return "user"; + } + + virtual std::string message( int ev ) const + { + char buffer[ 256 ]; + std::sprintf( buffer, "user message %d", ev ); + + return buffer; + } + + virtual boost::system::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT + { + if( ev == 4 ) + { + return boost::system::error_condition( EMFILE, boost::system::generic_category() ); + } + else if( ev == 5 ) + { + return boost::system::error_condition( EACCES, boost::system::generic_category() ); + } + else + { + return boost::system::error_condition( ev, *this ); + } + } + + virtual bool equivalent( int code, const boost::system::error_condition & condition ) const BOOST_NOEXCEPT + { + if( code == 4 && condition == make_error_condition( boost::system::errc::too_many_files_open_in_system ) ) + { + return true; + } + + if( code == 4 && condition == make_error_condition( boost::system::errc::too_many_files_open ) ) + { + return true; + } + + return default_error_condition( code ) == condition; + } + + // virtual bool equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT; +}; + +boost::system::error_category const & user_category() +{ + static user_category_impl cat_; + return cat_; +} + +static void test_user_category() +{ + boost::system::error_category const & bt = user_category(); + std::error_category const & st = bt; + + BOOST_TEST_CSTR_EQ( bt.name(), st.name() ); + + { + int ev = 5; + BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) ); + + { + boost::system::error_code bc( ev, bt ); + + BOOST_TEST_EQ( bc.value(), ev ); + BOOST_TEST_EQ( &bc.category(), &bt ); + + std::error_code sc( bc ); + + BOOST_TEST_EQ( sc.value(), ev ); + BOOST_TEST_EQ( &sc.category(), &st ); + } + + { + boost::system::error_condition bn = bt.default_error_condition( ev ); + BOOST_TEST( bt.equivalent( ev, bn ) ); + + std::error_condition sn( bn ); + BOOST_TEST( st.equivalent( ev, sn ) ); + } + } + + { + int ev = 4; + BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) ); + + { + boost::system::error_code bc( ev, bt ); + + BOOST_TEST_EQ( bc.value(), ev ); + BOOST_TEST_EQ( &bc.category(), &bt ); + + std::error_code sc( bc ); + + BOOST_TEST_EQ( sc.value(), ev ); + BOOST_TEST_EQ( &sc.category(), &st ); + } + + { + boost::system::error_condition bn = bt.default_error_condition( ev ); + BOOST_TEST( bt.equivalent( ev, bn ) ); + + std::error_condition sn( bn ); + BOOST_TEST( st.equivalent( ev, sn ) ); + } + + { + boost::system::error_condition bn = make_error_condition( boost::system::errc::too_many_files_open_in_system ); + BOOST_TEST( bt.equivalent( ev, bn ) ); + + std::error_condition sn( bn ); + BOOST_TEST( st.equivalent( ev, sn ) ); + } + + { + boost::system::error_condition bn = make_error_condition( boost::system::errc::too_many_files_open ); + BOOST_TEST( bt.equivalent( ev, bn ) ); + + std::error_condition sn( bn ); + BOOST_TEST( st.equivalent( ev, sn ) ); + } + } +} + +// test_user2_category + +enum user2_errc +{ + my_enoent = 1, + my_einval, + my_other +}; + +class user2_category_impl: public boost::system::error_category +{ +public: + + virtual const char * name() const BOOST_NOEXCEPT + { + return "user2"; + } + + virtual std::string message( int ev ) const + { + char buffer[ 256 ]; + std::sprintf( buffer, "user2 message %d", ev ); + + return buffer; + } + + virtual boost::system::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT + { + return boost::system::error_condition( ev, *this ); + } + + virtual bool equivalent( int code, const boost::system::error_condition & condition ) const BOOST_NOEXCEPT + { + return default_error_condition( code ) == condition; + } + + virtual bool equivalent( const boost::system::error_code & code, int condition ) const BOOST_NOEXCEPT + { + if( code.category() == *this ) + { + return condition == code.value(); + } + else if( condition == my_enoent ) + { + return code == boost::system::errc::no_such_file_or_directory; + } + else if( condition == my_einval ) + { + return code == boost::system::errc::invalid_argument; + } + else + { + return false; + } + } +}; + +boost::system::error_category const & user2_category() +{ + static user2_category_impl cat_; + return cat_; +} + +static void test_user2_category() +{ + boost::system::error_category const & bt = user2_category(); + std::error_category const & st = bt; + + int ev = my_enoent; + + boost::system::error_condition bn( ev, bt ); + + BOOST_TEST_EQ( bn.value(), ev ); + BOOST_TEST_EQ( &bn.category(), &bt ); + + boost::system::error_code bc = make_error_code( boost::system::errc::no_such_file_or_directory ); + + BOOST_TEST( bc == bn ); + + std::error_condition sn( bn ); + + BOOST_TEST_EQ( sn.value(), ev ); + BOOST_TEST_EQ( &sn.category(), &st ); + + std::error_code sc( bc ); + + BOOST_TEST( sc == sn ); +} + +// + +int main() +{ + std::cout + << "The version of the C++ standard library being used" + " supports header so interoperation will be tested.\n"; + test_generic_category(); + test_system_category(); + test_user_category(); + test_user2_category(); + + return boost::report_errors(); +} + +#endif