errinfo_errno.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef BOOST_EXCEPTION_F0EE17BE6C1211DE87FF459155D89593
  5. #define BOOST_EXCEPTION_F0EE17BE6C1211DE87FF459155D89593
  6. #include <boost/exception/info.hpp>
  7. #include <errno.h>
  8. #include <string.h>
  9. #ifndef BOOST_EXCEPTION_ENABLE_WARNINGS
  10. #if __GNUC__*100+__GNUC_MINOR__>301
  11. #pragma GCC system_header
  12. #endif
  13. #ifdef __clang__
  14. #pragma clang system_header
  15. #endif
  16. #ifdef _MSC_VER
  17. #pragma warning(push,1)
  18. #pragma warning(disable:4996)
  19. #endif
  20. #endif
  21. namespace
  22. boost
  23. {
  24. typedef error_info<struct errinfo_errno_,int> errinfo_errno;
  25. //Usage hint:
  26. //if( c_function(....)!=0 )
  27. // BOOST_THROW_EXCEPTION(
  28. // failure() <<
  29. // errinfo_errno(errno) <<
  30. // errinfo_api_function("c_function") );
  31. inline
  32. std::string
  33. to_string( errinfo_errno const & e )
  34. {
  35. std::ostringstream tmp;
  36. int v=e.value();
  37. tmp << '[' << error_info_name(e) << "] = " << v << ", \"" << strerror(v) << "\"\n";
  38. return tmp.str();
  39. }
  40. }
  41. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  42. #pragma warning(pop)
  43. #endif
  44. #endif