errinfo_errno.hpp 914 B

1234567891011121314151617181920212223242526272829303132333435
  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. namespace
  10. boost
  11. {
  12. typedef error_info<struct errinfo_errno_,int> errinfo_errno;
  13. //Usage hint:
  14. //if( c_function(....)!=0 )
  15. // BOOST_THROW_EXCEPTION(
  16. // failure() <<
  17. // errinfo_errno(errno) <<
  18. // errinfo_api_function("c_function") );
  19. inline
  20. std::string
  21. to_string( errinfo_errno const & e )
  22. {
  23. std::ostringstream tmp;
  24. int v=e.value();
  25. tmp << v << ", \"" << strerror(v) << "\"";
  26. return tmp.str();
  27. }
  28. }
  29. #endif