Update of /cvsroot/boost/boost/libs/system/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv24787/src
Modified Files:
Tag: c++0x
error_code.cpp
Log Message:
error_code op== and != now distinguish between portable and specific cases.
Revert some other changes as unhelpful.
Index: error_code.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/system/src/error_code.cpp,v
retrieving revision 1.8.2.5
retrieving revision 1.8.2.6
diff -u -d -r1.8.2.5 -r1.8.2.6
--- error_code.cpp 26 Jul 2007 20:22:20 -0000 1.8.2.5
+++ error_code.cpp 30 Jul 2007 02:03:39 -0000 1.8.2.6
@@ -198,15 +198,101 @@
// standard error categories -------------------------------------------//
+ class posix_error_category : public error_category
+ {
+ public:
+ const std::string & name() const;
+ posix::posix_errno posix( int ev ) const;
+ std::string message( int ev ) const;
+ };
+
class system_error_category : public error_category
{
public:
const std::string & name() const;
posix::posix_errno posix( int ev ) const;
+ std::string message( int ev ) const;
};
+ const posix_error_category posix_category_const;
const system_error_category system_category_const;
+ // posix_error_category implementation ---------------------------------//
+
+ const std::string & posix_error_category::name() const
+ {
+ static const std::string s( "POSIX" );
+ return s;
+ }
+
+ posix_errno posix_error_category::posix( int ev ) const
+ {
+ return static_cast<posix_errno>(ev);
+ }
+
+ std::string posix_error_category::message( int ev ) const
+ {
+ // strerror_r is preferred because it is always thread safe,
+ // however, we fallback to strerror in certain cases because:
+ // -- Windows doesn't provide strerror_r.
+ // -- HP and Sundo provide strerror_r on newer systems, but there is
+ // no way to tell if is available at runtime and in any case their
+ // versions of strerror are thread safe anyhow.
+ // -- Linux only sometimes provides strerror_r.
+ // -- Tru64 provides strerror_r only when compiled -pthread.
+ // -- VMS doesn't provide strerror_r, but on this platform, strerror is
+ // thread safe.
+ # if defined(BOOST_WINDOWS_API) || defined(__hpux) || defined(__sun)\
+ || (defined(__linux) && (!defined(__USE_XOPEN2K) ||
defined(BOOST_SYSTEM_USE_STRERROR)))\
+ || (defined(__osf__) && !defined(_REENTRANT))\
+ || (defined(__vms))
+ const char * c_str = std::strerror( ev );
+ return std::string( c_str ? c_str : "invalid_argument" );
+ # else
+ char buf[64];
+ char * bp = buf;
+ std::size_t sz = sizeof(buf);
+ # if defined(__CYGWIN__) || defined(__USE_GNU)
+ // Oddball version of strerror_r
+ const char * c_str = strerror_r( ev, bp, sz );
+ return std::string( c_str ? c_str : "invalid_argument" );
+ # else
+ // POSIX version of strerror_r
+ int result;
+ for (;;)
+ {
+ // strerror_r returns 0 on success, otherwise ERANGE if buffer too
small,
+ // invalid_argument if ev not a valid error number
+ if ( (result = strerror_r( ev, bp, sz )) == 0 )
+ break;
+ else
+ {
+ # if defined(__linux)
+ // Linux strerror_r returns -1 on error, with error number in errno
+ result = errno;
+ # endif
+ if ( result != ERANGE ) break;
+ if ( sz > sizeof(buf) ) std::free( bp );
+ sz *= 2;
+ if ( (bp = static_cast<char*>(std::malloc( sz ))) == 0 )
+ return std::string( "ENOMEM" );
+ }
+ }
+ try
+ {
+ std::string msg( ( result == invalid_argument ) ? "invalid_argument" :
bp );
+ if ( sz > sizeof(buf) ) std::free( bp );
+ sz = 0;
+ return msg;
+ }
+ catch(...)
+ {
+ if ( sz > sizeof(buf) ) std::free( bp );
+ throw;
+ }
+ # endif
+ # endif
+ }
// system_error_category implementation --------------------------------//
const std::string & system_error_category::name() const
@@ -228,12 +314,58 @@
return boost::system::posix::no_posix_equivalent;
}
+# if !defined( BOOST_WINDOWS_API )
+
+ std::string native_error_category::message( boost::int_least32_t ev ) const
+ {
+ return posix_category.message( ev );
+ }
+# else
+// TODO:
+
+//Some quick notes on the implementation (sorry for the noise if
+//someone has already mentioned them):
+//
+//- The ::LocalFree() usage isn't exception safe.
+//
+//See:
+//
+//<http://boost.cvs.sourceforge.net/boost/boost/boost/asio/system_exception.hpp?revision=1.1&view=markup>
+//
+//in the implementation of what() for an example.
+//
+//Cheers,
+//Chris
+ std::string system_error_category::message( int ev ) const
+ {
+ LPVOID lpMsgBuf;
+ ::FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ ev,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPSTR) &lpMsgBuf,
+ 0,
+ NULL
+ );
+ std::string str( static_cast<LPCSTR>(lpMsgBuf) );
+ ::LocalFree( lpMsgBuf ); // free the buffer
+ while ( str.size()
+ && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') )
+ str.erase( str.size()-1 );
+ return str;
+ }
+# endif
} // unnamed namespace
namespace boost
{
namespace system
{
+ BOOST_SYSTEM_DECL const error_category & posix_category
+ = posix_category_const;
BOOST_SYSTEM_DECL const error_category & system_category
= system_category_const;
} // namespace system
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs