system_error.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_DLL_SYSTEM_ERROR_HPP
  7. #define BOOST_DLL_SYSTEM_ERROR_HPP
  8. #include <boost/config.hpp>
  9. #include <boost/predef/os.h>
  10. #include <boost/system/error_code.hpp>
  11. #include <boost/system/system_error.hpp>
  12. #include <boost/throw_exception.hpp>
  13. #if !BOOST_OS_WINDOWS
  14. # include <dlfcn.h>
  15. #endif
  16. #ifdef BOOST_HAS_PRAGMA_ONCE
  17. # pragma once
  18. #endif
  19. namespace boost { namespace dll { namespace detail {
  20. inline void reset_dlerror() BOOST_NOEXCEPT {
  21. #if !BOOST_OS_WINDOWS
  22. const char* const error_txt = dlerror();
  23. (void)error_txt;
  24. #endif
  25. }
  26. inline void report_error(const boost::system::error_code& ec, const char* message) {
  27. #if !BOOST_OS_WINDOWS
  28. const char* const error_txt = dlerror();
  29. if (error_txt) {
  30. boost::throw_exception(
  31. boost::system::system_error(
  32. ec,
  33. message + std::string(" (dlerror system message: ") + error_txt + std::string(")")
  34. )
  35. );
  36. }
  37. #endif
  38. boost::throw_exception(
  39. boost::system::system_error(
  40. ec, message
  41. )
  42. );
  43. }
  44. }}} // boost::dll::detail
  45. #endif // BOOST_DLL_SYSTEM_ERROR_HPP