system_error.hpp 1.4 KB

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