mirror of
https://github.com/boostorg/system.git
synced 2025-07-29 20:17:13 +02:00
Use strerror_r on glibc
This commit is contained in:
69
include/boost/system/detail/generic_category.hpp
Normal file
69
include/boost/system/detail/generic_category.hpp
Normal file
@ -0,0 +1,69 @@
|
||||
// Implementation details of generic_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
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if defined(__GLIBC__)
|
||||
|
||||
// std::strerror is not thread-safe on glibc (for no reason)
|
||||
// glibc also has two incompatible strerror_r definitions (for no reason)
|
||||
|
||||
inline char const * strerror_r_helper( char const * r, char const * )
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
inline char const * strerror_r_helper( int r, char const * buffer )
|
||||
{
|
||||
return r == 0? buffer: "Unknown error";
|
||||
}
|
||||
|
||||
inline std::string generic_error_category_message( int ev )
|
||||
{
|
||||
char buffer[ 128 ];
|
||||
return strerror_r_helper( strerror_r( ev, buffer, sizeof( buffer ) ), buffer );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// std::strerror is thread-safe on everything else, incl. Windows
|
||||
|
||||
inline std::string generic_error_category_message( int ev )
|
||||
{
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4996 )
|
||||
# endif
|
||||
|
||||
char const * m = std::strerror( ev );
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( pop )
|
||||
# endif
|
||||
|
||||
return m? m: "Unknown error";
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
@ -17,7 +17,6 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <cstring>
|
||||
|
||||
// TODO: undef these macros if not already defined
|
||||
#include <boost/cerrno.hpp>
|
||||
@ -761,38 +760,19 @@ inline bool error_category::equivalent( const error_code & code, int condition )
|
||||
return *this == code.category() && code.value() == condition;
|
||||
}
|
||||
|
||||
// generic_error_category implementation
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline char const * generic_error_category_message( int ev )
|
||||
{
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4996 )
|
||||
#endif
|
||||
|
||||
char const * m = std::strerror( ev );
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
return m? m: "Unknown error";
|
||||
}
|
||||
|
||||
inline std::string generic_error_category::message( int ev ) const
|
||||
{
|
||||
return generic_error_category_message( ev );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
// generic_error_category implementation
|
||||
|
||||
#include <boost/system/detail/generic_category.hpp>
|
||||
|
||||
inline std::string boost::system::detail::generic_error_category::message( int ev ) const
|
||||
{
|
||||
return generic_error_category_message( ev );
|
||||
}
|
||||
|
||||
// system_error_category implementation
|
||||
|
||||
#if defined(BOOST_WINDOWS_API)
|
||||
|
Reference in New Issue
Block a user