errinfo_errno.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 UUID_F0EE17BE6C1211DE87FF459155D89593
  5. #define UUID_F0EE17BE6C1211DE87FF459155D89593
  6. #include <boost/exception/info.hpp>
  7. #include <errno.h>
  8. #include <string.h>
  9. #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  10. #pragma GCC system_header
  11. #endif
  12. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  13. #pragma warning(push,1)
  14. #pragma warning(disable:4996)
  15. #endif
  16. namespace
  17. boost
  18. {
  19. typedef error_info<struct errinfo_errno_,int> errinfo_errno;
  20. //Usage hint:
  21. //if( c_function(....)!=0 )
  22. // BOOST_THROW_EXCEPTION(
  23. // failure() <<
  24. // errinfo_errno(errno) <<
  25. // errinfo_api_function("c_function") );
  26. inline
  27. std::string
  28. to_string( errinfo_errno const & e )
  29. {
  30. std::ostringstream tmp;
  31. int v=e.value();
  32. tmp << '[' << error_info_name(e) << "] = " << v << ", \"" << strerror(v) << "\"\n";
  33. return tmp.str();
  34. }
  35. }
  36. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  37. #pragma warning(pop)
  38. #endif
  39. #endif