ISIS Core Library 0.7.2 (api 3.0.0)
|
00001 #include "common.hpp" 00002 00003 #ifdef WIN32 00004 #include <boost/lexical_cast.hpp> 00005 #endif 00006 00007 namespace isis 00008 { 00009 namespace util 00010 { 00011 00012 std::string getLastSystemError() 00013 { 00014 #ifdef WIN32 00015 std::string ret; 00016 LPTSTR s; 00017 DWORD err = GetLastError(); 00018 00019 if( ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 00020 NULL, 00021 err, 00022 0, 00023 ( LPTSTR )&s, 00024 0, 00025 NULL ) == 0 ) { /* failed */ 00026 ret = std::string( "Unknown error " ) + boost::lexical_cast<std::string>( err ); 00027 } else { /* success */ 00028 ret = s; 00029 ret.resize( ret.rfind( '\r' ) ); //FormatMessage appends a newline 00030 ::LocalFree( s ); 00031 } 00032 00033 return ret; 00034 #else 00035 return strerror( errno ); 00036 #endif 00037 } 00038 } 00039 }