1 // Implementation details of generic_error_category
3 // Copyright 2018 Peter Dimov
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 // See library home page at http://www.boost.org/libs/system
21 #if defined(__GLIBC__)
23 // glibc has two incompatible strerror_r definitions
25 inline char const * strerror_r_helper( char const * r, char const * ) BOOST_NOEXCEPT
30 inline char const * strerror_r_helper( int r, char const * buffer ) BOOST_NOEXCEPT
32 return r == 0? buffer: "Unknown error";
35 inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
37 return strerror_r_helper( strerror_r( ev, buffer, len ), buffer );
40 inline std::string generic_error_category_message( int ev )
43 return generic_error_category_message( ev, buffer, sizeof( buffer ) );
48 // std::strerror is thread-safe on everything else, incl. Windows
50 # if defined( BOOST_MSVC )
51 # pragma warning( push )
52 # pragma warning( disable: 4996 )
53 # elif defined(__clang__) && defined(__has_warning)
54 # pragma clang diagnostic push
55 # if __has_warning("-Wdeprecated-declarations")
56 # pragma clang diagnostic ignored "-Wdeprecated-declarations"
60 inline std::string generic_error_category_message( int ev )
62 char const * m = std::strerror( ev );
63 return m? m: "Unknown error";
66 inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
79 char const * m = std::strerror( ev );
81 if( m == 0 ) return "Unknown error";
83 std::strncpy( buffer, m, len - 1 );
89 # if defined( BOOST_MSVC )
90 # pragma warning( pop )
91 # elif defined(__clang__) && defined(__has_warning)
92 # pragma clang diagnostic pop